Ti nspire programming - definition of variables - ti-nspire

I'm trying to make a script in order to perform those two equation with summation:
((−b*σ*yn)/(2))+∑(−σ*(1-((yi)/(yn)))*ab*nbi,i,1,Nf)
and this:
((b*s*yn^(2))/(3))+∑(−σ*(1-((yi)/(yn)))(yi-yn)*ab*nbi,i,1,Nf)
My code is:
Prgm
Local b,h,n,nf,n_tot,mf,ub,lb,hi,ii,msg,y,yn,σ,ab,eq1,eq2
Disp ""
Request "b :",b
Request "h :",h
Request "Ab :",ab
Request "N : ",n
Request "Mf : ",mf
Request "N° tot : ",n_tot
Request "N° over N-A : ",nf
newMat(nf,2)→hi
For ii,1,nf,1
Request "h i-i:",msg
msg→hi[ii,1]
Request "b i-i:",msg
msg→hi[ii,2]
EndFor
Disp "matrix",hi
newMat(1,1)→eq1
newMat(1,1)→eq2
For ii,1,nf,1
((-b*σ*yn)/2) + (−σ*(1-((hi[ii,1])/(yn)))*ab*hi[ii,2])→eq1[ii,1]
((b*s*yn^2)/3) + (−σ*(1-((hi[ii,1])/(yn)))*(hi[ii,1]-
yn)*ab*hi[ii,2])→eq2[ii,1]
EndFor
Disp "eq1:",eq1
Disp "eq2:",eq2
Disp "solution",solve(eq1[1,1]=n and eq2[1,1]=mf+n(0.5*h+yn),{yn,σ})|yn>0
EndPrgm
But i get : "Error: Variable is not defined"
I do not understand why i get this error, what i'm doing wrong?
Any hints will be appreciated,i'm new in programming.

Solved: the problem was in Local variable definition.
Define LibPub bj_semi_rgd_fl()=
Prgm
Local b,h,ab,n,mf,nf,hi,msg,i,j
Request "Larghezza flangia :",b
Request "Lunghezza flangia :",h
Request "Sezione bullone :",ab
Request "N : ",n
Request "Mf : ",mf
Request "N° file sopra A-N : ",nf
hi:=newMat(nf,2)
For i,1,nf,1
Request "altezza della fila i-esima:",msg
hi[i,1]:=msg
Request "bulloni per fila i-esima:",msg
hi[i,2]:=msg
EndFor
eq1:=0
eq2:=0
For j,1,nf,1
eq1:=eq1+−σ*(1-((hi[j,1])/(yn)))*ab*hi[j,2]
eq2:=eq2+−σ*(1-((hi[j,1])/(yn)))*(hi[j,1]-yn)*ab*hi[j,2]
EndFor
Disp "+++Risultato+++"
Disp "",solve(((−b*σ*yn)/(2))+eq1=n and ((b*σ*yn^(2))/(3))+eq2=mf+n*(0.5*h+yn),
{yn,σ})|yn>0
Disp "++++++++++++"
DelVar eq1,eq2,yn,σ
EndPrgm
So I've just cancelled the variables that are used in the command "solve()". That's all.

Related

Deployment Azur function from Business Central

I try to deploy the Azure function by using Rest API and zip-archive of solution.
It works properly in Postman.
I've found advice on how to upload mp3 files and develop a solution for my task.
But when I try to create a payload for request by AL-code for Business Central (file have been uploaded to instr):
CR := 13;
LF := 10;
NewLine += '' + CR + LF;
httpHeader.Clear();
TempBlob.CreateOutStream(PayloadOutStream);
PayloadOutStream.WriteText('--boundary' + NewLine);
PayloadOutStream.WriteText(StrSubstNo('Content-Disposition: form-data; name="file"; filename="%1"', filename) + NewLine);
PayloadOutStream.WriteText('Content-Type: application/zip' + NewLine);
PayloadOutStream.WriteText(NewLine);
CopyStream(PayloadOutStream, InStr);
PayloadOutStream.WriteText(NewLine);
PayloadOutStream.WriteText('--boundary');
PayloadOutStream.WriteText(NewLine);
TempBlob.CreateInStream(PayloadInStream);
Content.WriteFrom(PayloadInStream);
Content.GetHeaders(httpHeader);
if httpHeader.Contains('Content-Type') then httpHeader.Remove('Content-Type');
httpHeader.Add('Content-Type', 'multipart/form-data;boundary=boundary');
httpRequest := CreateHttpRequestMessage(Content, 'Post', RequestURI);
Client.Clear();
Client.DefaultRequestHeaders.Add('Authorization', StrSubstNo('Bearer %1', token));
if Client.Send(httpRequest, httpResponse) then begin
httpResponse.Content().ReadAs(responseText);
Message(responseText);
end
else
Error(RequestErrorMsg);
I received an error in the response message from the deployment process like this:
{"Message":"An error has occurred.","ExceptionMessage":"Number of entries expected in End Of Central Directory does not correspond to number of entries in Central Directory.","ExceptionType":"System.IO.InvalidDataException","StackTrace":" at System.IO.Compression.ZipArchive.ReadCentralDirectory()\r\n at System.IO.Compression.ZipArchive.get_Entries()\r\n at Kudu.Core.Infrastructure.ZipArchiveExtensions.Extract(ZipArchive archive, String directoryName, ITracer tracer, Boolean doNotPreserveFileTime) in C:\\Kudu Files\\Private\\src\\master\\Kudu.Core\\Infrastructure\\ZipArchiveExtensions.cs:line 114\r\n at Kudu.Services.Deployment.PushDeploymentController.<>c__DisplayClass21_0.<LocalZipFetch>b__1() in C:\\Kudu Files\\Private\\src\\master\\Kudu.Services\\Deployment\\PushDeploymentController.cs:line 746\r\n at System.Threading.Tasks.Task.InnerInvoke()\r\n at System.Threading.Tasks.Task.Execute()......
I believe, something is wrong when I build the payload. Could you give me advice on how I have to build the body of request for my case?

How to access custom header from AWS Lambda Authorizer?

I have created an Authorizer in AWS API Gateway. This Authorizer refers to a Lambda Function.
I am passing the following values in header, to the API Endpoint using Postman.
{
"type":"TOKEN",
"authorizationToken": "testing2",
"methodArn": "arn:aws:execute-api:us-west-2:444456789012:ymy8tbxw7b/*/GET/"
}
The above header values are received in the Lambda Function. I can see this through the logs in CloudWatch.
I want to pass additional value 'clientID' in the header. So I pass the following values in the header from postman.
{
"type":"TOKEN",
"authorizationToken": "testing2",
"methodArn": "arn:aws:execute-api:us-west-2:123456789012:ymy8tbxw7b/*/GET/",
"clientID" : "1000"
}
In this case, the Lambda function does not get the clientID. I checked various threads in SO, and understood that this can be achieved mapping header. So I did the following.
In the "Method Execution" section of the API method, I created a new header clientID. In the "Integration Request" section, under "HTTP Headers" section I provided the following value
Name: clientID
Mapped from: method.request.header.clientID
After doing the above, I deployed the API and tried to call the method from Postman, but the clientID is shown undefined. Following is the code that I have written in Lambda Function
exports.handler = function(event, context, callback) {
var clientid = event.clientID;
//I always get event.clientID undefined
console.log("The client ID is:" + event.clientID);
}
EDIT
Following is the error from the CloudWatch Log.
START RequestId: 274c6574-dea5-4009-b777-a929f84b9a9d Version: $LATEST
2019-09-19T09:40:25.944Z 274c6574-dea5-4009-b777-a929f84b9a9d INFO The client ID is:undefined
2019-09-19T09:40:25.968Z 274c6574-dea5-4009-b777-a929f84b9a9d ERROR Invoke Error
{
"errorType": "Error",
"errorMessage": "Unauthorized",
"stack": [
"Error: Unauthorized",
" at _homogeneousError (/var/runtime/CallbackContext.js:13:12)",
" at postError (/var/runtime/CallbackContext.js:30:51)",
" at callback (/var/runtime/CallbackContext.js:42:7)",
" at /var/runtime/CallbackContext.js:105:16",
" at Runtime.exports.handler (/var/task/index.js:40:4)",
" at Runtime.handleOnce (/var/runtime/Runtime.js:66:25)",
" at process._tickCallback (internal/process/next_tick.js:68:7)"
]
}
I have understood why I was not getting the value in the header. I have done the following
1) Instead of type TOKEN, I used type REQUEST in the header. I understood this by reading the following link. This link also contains code for Request type.
https://docs.aws.amazon.com/apigateway/latest/developerguide/apigateway-use-lambda-authorizer.html
2) I removed all the mapping from Method Request and Integration Request.
3) Deployed the API.

Matlab RESTful PUT Command - net.http - nesting body values

I am using Matlab's matlab.net.http library to launch get, put and post commands to a website. I can successfully launch get and post commands.
For example:
MyBody = matlab.net.http.MessageBody(struct('Id',YYYYYY,'WindfarmId',XXX,'Month','YYYY-MM-DD'));
Request = matlab.net.http.RequestMessage;
Request.Method = 'POST';
Request.Header = matlab.net.http.HeaderField('Content-Type','application/json','Authorization',['Basic ' matlab.net.base64encode([Username ':' Password])]);
Request.Body = MyBody;
uri = matlab.net.URI(ENTERURLHERE);
Response = Request.send(uri,MyHTTPOptions);
This works well. However using a PUT command I have to enter the equiavlent of this body (written in curl syntax):
-d '{ "InputValues": [ {"MetricLevelAId": 1, "MetricLevelBId": 1, "InputMetricId": 7, "Value": 56 } ] }'
I tried this:
data_InputValues = struct ('MetricLevelAId',1,'MetricLevelBId',1,'InputMetricId',7,'Value',56);
MyBody = matlab.net.http.MessageBody(struct('InputValues',dataInputValues));
However I keep receiving the following 'Bad Request' response from the server:
"Input values required"
I think this is linked to the way Matlab interprets the body part of the request and passes it to the server, i.e. it cannot pass the nested struct correctly. Anyone got any ideas how to solve this?
N.B. potentially linked to Translating curl into Matlab/Webwrite (it is dealing with a nested value)

How can I use a String in an URL?

I'm trying to create Web Service where I can send a stardog request using a HTTP GET method. My problem is that the stardog request are using a few symbol that aren't allowed in a URL, like ? or ; and I'm trying to not force the user to manually convert it to %3F or %3B.
So I want my URL to look like this :
localhost:8080/WebServiceTest/query?select="SELECT * WHERE {?s ?p ?o}"
My Jersey annotations are the following:
#GET
#Path("/query")
#Produces(MediaType.APPLICATION_JSON + ";charset=utf-8")
public String execQuery(#QueryParam("select") String selectQuery, #QueryParam("update") String updateQuery) {
Does anyone know if this is possible? And if it is, how can I do that?
If you use Javascript/ECMAScript 5.1++ on client side you can convert a string to a uri string format. Use the method
encodeURIComponent(str);
which is explained here.
It is also possible to replace the ? ; chars by their %-represetation. (In the case of using cUrl)
(SPACE) ! " # $ % & ' ( ) * + , / : ;
%20 %21 %22 %23 %24 %25 %26 %27 %28 %29 %2A %2B %2C %2F %3A %3B
= ? # [ ]
%3D %3F %40 %5B %5D

sinatra rest-client etag

My goal is to address "lost update problem" (see http://www.w3.org/1999/04/Editing/) in PUT operations.
I am using sinatra, and as a client I use rest_client. How I can check if it works? My client always return 200 code. Am I using arguments of calling it correctly? (PUT itself works)
sinatra code:
put '/players/:id' do |id|
etag 'something'
if Player[id].nil? then
halt 404
end
begin
data = JSON.parse(params[:data])
pl = Player[id]
pl.name = data['name']
pl.position = data['position']
if pl.save
"Resource modified."
else
status 412
redirect '/players'
end
rescue Sequel::DatabaseError
409 #Conflict - The request was unsuccessful due to a conflict in the state of the resource.
rescue Exception => e
400
puts e.message
end
end
client invocation:
player = {"name" => "John Smith", "position" => "def"}.to_json
RestClient.put('http://localhost:4567/players/1', {:data => player, :content_type => :json, :if_none_match => '"something"'}){ |response, request, result, &block|
p response.code.to_s + " " + response
}
I tried already to put :if_none_match => "something", I tried :if_match. Nothing changes.
How I can put headers into RestClient request?
How to obtain sth different than 200 status? (ie 304 not modified)?
Your payload and headers are in the same hash. You have to specify the headers for RestClient in second hash. Try:
player = {"name" => "John Smith", "position" => "def"}.to_json
headers = {:content_type => :json, :if_none_match => '"something"'}
RestClient.put('http://localhost:4567/players/1', {:data => player}, headers) do |response, request, result, &block|
p response.code.to_s + " " + response
end
I am not sure if RestClient translates the headers correctly. If the above doesn't work, try it with:
headers = {'Content-Type' => :json, 'If-None-Match' => '"something"'}