I am using VBScript in a Manifold GIS Database to verify the distance between two longitude and latitude points using Trig function. The script for finding the distance run without any problems but the script for verifying whether the O-D is valid had syntax error. I really hope any of you could help me with this problem.
There were 2 new active columns that I created : Distance and VerifyDistance. Distance column was created to find the distance using Trig function. It ran successfuly but may need improvements in its messy structure. The VerifyDistance used the IF conditions and checked the value in another column named "Valid O/D". If the value is "OK", it will return the Distance value; otherwise, it will return a text value saying "O-D points are invalid" in this column.
As you can see, I am a newb in programming language. The VBScript can be seen below:
Function Distance
Distance = sqr((111.21*Record.Data("Work Y-coord") - 111.21*Record.Data("Home Y-coord"))^2 + (85.30*Record.Data("Work X-coord") - 85.30*Record.Data("Home X-coord"))^2)
End Function
Function VerifyDistance
If Record.Data("Valid O/D") = "OK"
VerifyDistance = Record.Data("Distance")
'document.write("Invalid O-D Points")
Else
VerifyDistance = "O-D Points are invalid."
End If
End Function
You are missing Then here.
If Record.Data("Valid O/D") = "OK" Then
Related
I have a program to find principal stresses. In it, is a cubic equation that I would like to solve and display 3 results. Here are my questions:
1. is solve() function correct one to use in ti-basic to solve the cubic equation? if not, which is correct?
2. When executing the program in home screen how to display three values of cubic equation?
Here is my program:
princstr(xx,yy,zz,xy,xz,yz)
Prgm
a = xx+yy+zz
b = xx*yy+yy*zz+zz*xx-xy^2-yz^2+xz^2
c = xx*yy*zz+xy*yz*xz+xz*xy*yz-xz*yy*xz-xz*yy*xz-yz*yz*xx-zz*xy*xy
solve(s^3-a*s^2+b*s-c=0,s)
Return s
EndPrgm
In the home screen it just returs
Done
Thank you in advance!
P.s. Edits are welcome.
You are not displaying S. Return does not work like return in other languages. In TI-Basic, Return does not return a value; it return control to the calling program. If you want to display it, you should do
:Disp S
:Return
I have a mapping table, M:
And using this, I've performed a find & replace on string S which gives me the transformed string S':
S: {"z" "y" "g" "k"} -> S':{"z" "y" "h" "k"}
Now I wish to verify if my mapping transformation was actually applied to S'. The psudo-code I came up for doing so is as follows:
I. Call function searchCol(x, “h”); // returns true if “h” can be found in column x in M.
II. If searchCol(x, “h”); returns true {
// assume mapping transformation was not applied to S'
// S'' after transforming S': {“z”, “y”, “i”, “j”}
}
III.If searchCol(x, “h”); returns false {
// assume mapping transformation was already applied to S'
// do nothing
}
IV. // log and continue …
However, as you can see, for the case above the algorithm doesn't work. Does anyone know a better way of going about this?
Cheers for your help.
Note: As my codebase is in Java, if you do provide any code examples, I'd prefer it if you posted them in the same language :)
Can you instead keep track of transformations? There are some cases where it's impossible to determine if a transformation took place, imagine this mapping table:
x -> y
y -> x
Now given the String yxyxyxyx, was it already transformed? And how many times?
But even if your mapping table is free of circles, the only thing you can say is:
If the string contains a char that is on the left side and not on the right side,
then it was not yet transformed.
But if the above condition is not fulfilled, then you can not be sure of anything.
I am trying to calculate distance between two points in kilometers but it is giving me wrong.
location.each do |loc|
distance = Haversine.distance(28.6139, 77.209, loc[:lat].to_f, loc[:long].to_f).to_km
puts " #{distance}"
end
Here is the distance which I am getting and which is wrong
7385.99072855455
7383.795725224046
7392.13122601482
7391.537885880786
The data of the location is in my database
[{"id":1,"lat":28.6139,"lng":77.209,"location":"","object_id":1,"created_at":"2016-06-07T05:46:53.000Z","updated_at":"2016-06-07T05:46:53.000Z","object_type":"abc"},{"id":2,"lat":28.6692,"lng":77.4538,"location":"","object_id":2,"created_at":"2016-06-07T05:49:23.000Z","updated_at":"2016-06-07T05:49:23.000Z","object_type":"cde"},{"id":3,"lat":28.4595,"lng":77.0266,"location":"","object_id":3,"created_at":"2016-06-07T05:50:22.000Z","updated_at":"2016-06-07T05:50:22.000Z","object_type":"ggg"},{"id":4,"lat":28.4744,"lng":77.504,"location":"","object_id":4,"created_at":"2016-06-07T05:50:24.000Z","updated_at":"2016-06-07T05:50:24.000Z","object_type":"eerr"}]
You have a typo: loc[:long] instead of loc[:lng], the line should read:
Haversine.distance(28.6139, 77.209, loc[:lat].to_f, loc[:lng].to_f).to_km
You passed nil.to_f as _longitude of the second point. This is equivalent to passing 0
I am relatively new to Modelica (Dymola-environment) and I am getting very desperate/upset that I cannot solve such a simple problem as a random number generation in Modelica and I hope that you can help me out.
The simple function random produces a random number between 0 and 1 with an input seed seedIn[3] and produces the output seed seedOut[3] for the next time step or event. The call
(z,seedOut) = random(seedIn);
works perfectly fine.
The problem is that I cannot find a way in Modelica to compute this assignment over time by using the seedOut[3] as the next seedIn[3], which is very frustrating.
My simple program looks like this:
*model Randomgenerator
Real z;
Integer seedIn[3]( start={1,23,131},fixed=true), seedOut[3];
equation
(z,seedOut) = random(seedIn);
algorithm
seedIn := seedOut;
end Randomgenerator;*
I have tried nearly all possibilities with algorithm assignments, initial conditions and equations but none of them works. I just simply want to use seedOut in the next time step. One problem seems to be that when entering into the algorithm section, neither the initial conditions nor the values from the equation section are used.
Using the 'sample' and 'reinit' functions the code below will calculate a new random number at the frequency specified in 'sample'. Note the way of defining the "start value" of seedIn.
model Randomgenerator
Real seedIn[3] = {1,23,131};
Real z;
Real[3] seedOut;
equation
(z,seedOut) = random(seedIn);
when sample(1,1) then
reinit(seedIn,pre(seedOut));
end when;
end Randomgenerator;
The 'pre' function allows the use of the previous value of the variable. If this was not used, the output 'z' would have returned a constant value. Two things regarding the 'reinint' function, it requires use of 'when' and requires 'Real' variables/expressions hence seedIn and seedOut are now defined as 'Real'.
The simple "random" generator I used was:
function random
input Real[3] seedIn;
output Real z;
output Real[3] seedOut;
algorithm
seedOut[1] :=seedIn[1] + 1;
seedOut[2] :=seedIn[2] + 5;
seedOut[3] :=seedIn[3] + 10;
z :=(0.1*seedIn[1] + 0.2*seedIn[2] + 0.3*seedIn[3])/(0.5*sum(seedIn));
end random;
Surely there are other ways depending on the application to perform this operation. At least this will give you something to start with. Hope it helps.
Afternoon,
Im playing around with a little bidding script im trying to write. But im having trouble with formatNumber function.
currentBid = 50.51 'from database dataType double(16,2)
yourBid = isNumeric(Request("bid"))
If FormatNumber(yourBid,2) > FormatNumber(currentBid,2) Then
Response.Write"bid successful... woop woop"
else
Response.Write"you cant bid below the current asking price"
end if
But if i was to bid 1000 is writes "you cant bid below the current asking price"
Please advise
Regards
Shane
'Changed as advised
currentBid = 50.51 'value from database
If IsNumeric(Request.Form("bid")) Then
yourBid = CDbl(Request.Form("bid"))
end if
You have two issues here:
As Ekkehard mentioned, IsNumeric() returns a boolean. To test if the value is numeric and then store to your variable, use:
If IsNumeric(Request("bid")) Then yourBid = CDbl(Request("bid"))
FormatNumber() returns a string representation of a number. So you're comparing one string against another instead of one number against another. If you need to round your numbers to two decimals, use the Round() function instead:
If Round(yourBid,2) > Round(currentBid,2) Then
Edit: Proof.
MsgBox VarType(4) ' 2 = vbInteger
MsgBox VarType(FormatNumber(4)) ' 8 = vbString
The line
yourBid = isNumeric(Request("bid"))
does not store a valid number into yourBid, but the (booelan) result of the IsNumeric() function applied to Request("bid").
Change the line to
yourBid = CDbl(Request("bid"))
and see if your IF statement works as expected. Then add a proper validation for Request("bid").