1 Pages (7 items)
Working with Ranges - Rod - Messages
#1 Posted: 1/27/2014 12:25:43 PM
First time using SMath. Thank you so much for developing this software.
I am trying to reproduce a published Mathcad worksheet and am getting some unpredictable results.
Weird things happen with the range (3) command and understand how it works. However, my values, for E3(x3) do not match that of the published.
Please see the attached for your consideration. The range for x3:=x20,(x20+0.1)..x2MAX is in pink, the published MATHCAD is in green. It turns out that I can get the solution for one value at a time and it kind of matches when I set x3:= 0.01 for example. And when I make the optimization all to symbolic, it is as if all the values are summed into one value. Perhaps I am using the wrong thing to set ranges. I would greatly appreciate any insight to this.
Thank you so much!
ARS-4thed.sm (24 KiB) downloaded 54 time(s).
I am trying to reproduce a published Mathcad worksheet and am getting some unpredictable results.
Weird things happen with the range (3) command and understand how it works. However, my values, for E3(x3) do not match that of the published.
Please see the attached for your consideration. The range for x3:=x20,(x20+0.1)..x2MAX is in pink, the published MATHCAD is in green. It turns out that I can get the solution for one value at a time and it kind of matches when I set x3:= 0.01 for example. And when I make the optimization all to symbolic, it is as if all the values are summed into one value. Perhaps I am using the wrong thing to set ranges. I would greatly appreciate any insight to this.
Thank you so much!
ARS-4thed.sm (24 KiB) downloaded 54 time(s).
#2 Posted: 1/27/2014 3:30:48 PM
I reproduced this, saved as Mathcad file from SMath and there is no difference.
It seems there is a mistake somwhere. Pay attention that Mathcad index starts from 0 and SMath starts from 1
Regards,
Radovan
ARS-4thed-corr.sm (25 KiB) downloaded 39 time(s).
It seems there is a mistake somwhere. Pay attention that Mathcad index starts from 0 and SMath starts from 1
Regards,
Radovan
ARS-4thed-corr.sm (25 KiB) downloaded 39 time(s).
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
1 users liked this post
Davide Carpi 1/27/2014 6:50:00 PM
#3 Posted: 1/27/2014 4:28:22 PM
Thank you for looking into this with Mathcad. I don't have access to that software. However, I did check the equations, and they are correct with the published text.
If I manually set x3:=9.173E-5, I get E3(9.173E-5)= 1.843, x3:=0.01, E3(0.01)=203.285 should be 205.172 (different but close). x3:=0.1, E3(0.1)=2246.801 should be 2.249E3.
Now when x3 is a range, the first value is 2414.69. Wrong. when x3= 0.01, E3(0.01)=2613.756 and when x3=0.1, E3(0.1)=4421.926
Using the same equations, I would expect the same results. However, that does concern me that you produced the very same values for E3(x3) in math cad.
What is also strange, I can keep the x3 array that you expanded and evaluate E3 at specific numbers and get the correct values -or values that are close to the Mathcad values.
So E3(0.1)=203.285 keeping x3 as an array. E3(.14)= 3278.644. However, when I say E3(x3)= none of the values are correct.
Assuming I do have a mistake, the mistake should be the same if I choose to display E3(x3) or each individual E3 for a given array x3 or a given value.
If I manually set x3:=9.173E-5, I get E3(9.173E-5)= 1.843, x3:=0.01, E3(0.01)=203.285 should be 205.172 (different but close). x3:=0.1, E3(0.1)=2246.801 should be 2.249E3.
Now when x3 is a range, the first value is 2414.69. Wrong. when x3= 0.01, E3(0.01)=2613.756 and when x3=0.1, E3(0.1)=4421.926
Using the same equations, I would expect the same results. However, that does concern me that you produced the very same values for E3(x3) in math cad.
What is also strange, I can keep the x3 array that you expanded and evaluate E3 at specific numbers and get the correct values -or values that are close to the Mathcad values.
So E3(0.1)=203.285 keeping x3 as an array. E3(.14)= 3278.644. However, when I say E3(x3)= none of the values are correct.
Assuming I do have a mistake, the mistake should be the same if I choose to display E3(x3) or each individual E3 for a given array x3 or a given value.
#4 Posted: 1/27/2014 5:00:59 PM
I combed the forums again and a light bulb went off! Try installing Maxima and wrap my equations. Please see the attached, now working. I did retype the equations again, but the originals are correct. The SMath answers are now matching. I wonder if there is a way of doing this without having to do the wrappers? So I am submitting two worksheets. The first makes use of the Maxima() around my x20, and Q terms. The second only wraps the Maxima() around my E3(x3)= to get the answers. If I don't do this, then E3(x3) is a single number when keeping all my stuff using symbolic optimization. If I remove the Maxima all together, and change my x20, and Q's to use numeric optimization, then E3(x3) is back as an array, but with the wrong values again!
ARS-4thed-UsingMaxima-only-evaluating_E3.sm (24 KiB) downloaded 42 time(s).
ARS-4thed-UsingMaxima-only-evaluating_E3.sm (24 KiB) downloaded 42 time(s).
#5 Posted: 1/27/2014 5:44:44 PM
Ah, yes. If you define a function f(x) in Smath, and if you give to it a vector, then function will not perform on the every element of the vector - functions are not elemental like in Mathcad. If you want to do this in Smath you must use loops like this
[MATH=eng]for(i,range(1,length(x3)),el(E3,i):E3(el(x3,i)))[/MATH]
[MATH=eng]E3=mat(1.8432,205.1722,413.2555,626.0933,843.6854,1066.0319,1293.1328,1524.9881,1761.5977,2002.9617,2249.0801,2499.9529,2755.5801,3015.9616,3281.0975,3550.9878,16,1)[/MATH]
One should be careful about this. For instance this are quite different things (choose numerical optimization here)
[MATH=eng]f(x):x^2+2*x[/MATH] [MATH[eng]f(x3)=mat(0.1244,0.1444,0.1644,0.1844,0.2044,0.2244,0.2444,0.2644,0.2844,0.3044,0.3244,0.3444,0.3644,0.3844,0.4044,0.4244,16,1)[/MATH]
[MATH=eng]for(i,range(1,length(x3)),el(res,i):el(x3,i)^2+2*el(x3,i))[/MATH] [MATH=eng]res=mat(0.0002,0.0203,0.0406,0.0611,0.0818,0.1027,0.1238,0.1451,0.1666,0.1883,0.2102,0.2323,0.2546,0.2771,0.2998,0.3227,16,1)[/MATH]
Or to use Maxima, which uses the function elementally, on every element of a vector.
I hope this helped.
Regards,
Radovan
[MATH=eng]for(i,range(1,length(x3)),el(E3,i):E3(el(x3,i)))[/MATH]
[MATH=eng]E3=mat(1.8432,205.1722,413.2555,626.0933,843.6854,1066.0319,1293.1328,1524.9881,1761.5977,2002.9617,2249.0801,2499.9529,2755.5801,3015.9616,3281.0975,3550.9878,16,1)[/MATH]
One should be careful about this. For instance this are quite different things (choose numerical optimization here)
[MATH=eng]f(x):x^2+2*x[/MATH] [MATH[eng]f(x3)=mat(0.1244,0.1444,0.1644,0.1844,0.2044,0.2244,0.2444,0.2644,0.2844,0.3044,0.3244,0.3444,0.3644,0.3844,0.4044,0.4244,16,1)[/MATH]
[MATH=eng]for(i,range(1,length(x3)),el(res,i):el(x3,i)^2+2*el(x3,i))[/MATH] [MATH=eng]res=mat(0.0002,0.0203,0.0406,0.0611,0.0818,0.1027,0.1238,0.1451,0.1666,0.1883,0.2102,0.2323,0.2546,0.2771,0.2998,0.3227,16,1)[/MATH]
Or to use Maxima, which uses the function elementally, on every element of a vector.
I hope this helped.
Regards,
Radovan
When Sisyphus climbed to the top of a hill, they said: "Wrong boulder!"
1 users liked this post
Davide Carpi 1/27/2014 6:50:00 PM
#6 Posted: 1/27/2014 6:19:53 PM
It did thank you so much for that loop example too!
#7 Posted: 1/27/2014 7:50:47 PM
Using Maxima we could define a function Vec(expr), which does nothing else than calling Maxima(expr) just for using the mapping capabilities of Maxima. Really smart would be to have some operator representation of that function, let's say an overarrow.
Martin Kraska
Pre-configured portable distribution of SMath Studio: https://en.smath.info/wiki/SMath%20with%20Plugins.ashx
1 Pages (7 items)
-
New Posts
-
No New Posts