Question on passing units to functions - Сообщения
I have tried some calculations with Smath and got surprising answers ( surprising for me ). Now the question is
1. did I make an error ?
2. did I expect something that is not implemented ?
3. is there a bug in Smath ?
I´m sure, the comunity can pick the correct answer.
The first example is connected with the integral function and units. The underlying attempt was to calculate the rms value of a sinusoidal voltage.
( I hope the following screenshots are self-explanatory )

Continuing this example, I experienced some additional observation:

The second example deals with a user defined unit definition to express power in db.

The complete Smath file is contained in
https://smath.com/wiki/GetFile.aspx?File=q1%2fIntegral.zip
Regards
ofniw
It was already answered in some another post.
1. Do not use definite integration with units. Definite integration is numericaly implemented in SMath and not ment to work with units. Your experimentations with it showed that as well.
2.When you hoover with the mouse on dbwM(x) you could see that the symbolic processor have log(x) in the expression - this is not allowed with units. You just have to force the RHS of the function definition to use "eval" function. For instance you can put all the expression of the RHS of the function definition inside the "eval" or just put only "eval(x/1mW))" and the function will work as expected.
Regards,
Radovan
thank you very much for the immediate reply.
Regards
ofniw
because I think, one of the most valuable features Andrey ( thank you ) has built into his software is the use of units I have made some more calculations and test in using units.
I have learned a lot doing these examples, but some results remained unclear to me. Also, maybe I can provide some useful information for other users.
The first workbook, book1 https://smath.com/wiki/GetFile.aspx?File=q1%2fNoise_2.zip shows by example something which I think can be a general remark. I have found a number of cases were the result depends on the setting of the optimization. As in book1 at "Example 1, Line 1" there is no result. Setting the optimization to "None" as in "Example 2" gives a correct result.
BTW: Is there a possibility to change the default setting of the optimization flag ?
What surprised me in book1 is that in "Example 1, Line 2" I get a correct result.
With the second workbook https://smath.com/wiki/GetFile.aspx?File=q1%2fNoise_p1.zip I have attached I see no reason why the expressions in line 1.1, line 2.2 and line 2.6 don´t give a result.
In a former posting I had asked if it is possible to use the definite integral with units. I learned that this is not possible and it is also not meant to be possible. It was also mentioned, that the definite integral is calculated with the Simpson rule. In the workbook 3 https://smath.com/wiki/GetFile.aspx?File=q1%2fInteg.zip I have replaced the build in integral function, by the explicit Simpson integration as found in one of the example files. I think, this example shows, that it is possible, also with numerical integration, to use units. Maybe this could encourage Andrey to add this feature to the built in integral function, which would make things more comfortable.
Regards
Wolfgang
WroteThe first workbook, book1 https://smath.com/wiki/GetFile.aspx?File=q1%2fNoise_2.zip shows by example something which I think can be a general remark. I have found a number of cases were the result depends on the setting of the optimization. As in book1 at "Example 1, Line 1" there is no result. Setting the optimization to "None" as in "Example 2" gives a correct result.
BTW: Is there a possibility to change the default setting of the optimization flag ?
What surprised me in book1 is that in "Example 1, Line 2" I get a correct result.
With the second workbook https://smath.com/wiki/GetFile.aspx?File=q1%2fNoise_p1.zip I have attached I see no reason why the expressions in line 1.1, line 2.2 and line 2.6 don´t give a result.
I also can not fully understand what happened here.
- When you sum up the three parts and use numerical equal to ( = ) - Units do not match?
- When you sum up the three parts and use symbolical equal to ( -> ) - Result will appear?
- The result will be Ok if assigning to a variable and then presenting the variable numerically - Optimization must be set to Symbolical?
- The result will be wrong if assigning to a variable and then presenting the variable numerically - Optimization set to None?
- When you show up all the three parts, one by one, numerically - you will have the numerical answer with a slight differences in the presented units - it is presented in SMath default units.
I can only conclude that the mess might come up due to the complex expression which include units (look the expression whith the Optimization-None set). It might be expected that the expression with units and the power different than the integer numbers might have the unpredictable impact (we have sqrt(1/s) here). It seems that Symbolic engine can manage with this kind of problems, but do not understand why the numerical answer is complaining and the symbolic is not.
WroteIn a former posting I had asked if it is possible to use the definite integral with units. I learned that this is not possible and it is also not meant to be possible. It was also mentioned, that the definite integral is calculated with the Simpson rule. In the workbook 3 https://smath.com/wiki/GetFile.aspx?File=q1%2fInteg.zip I have replaced the build in integral function, by the explicit Simpson integration as found in one of the example files. I think, this example shows, that it is possible, also with numerical integration, to use units. Maybe this could encourage Andrey to add this feature to the built in integral function, which would make things more comfortable.
I think that there might be a mess here as well if the intrinsic integration in SMath is not designed to work with units. Until then, one can use the user defined integration functions, as you did yourself.
Regards
Radovan
I am unable to open these SMath files as they have been created using SMath 0.90 (Don't know where that comes from).
I am currently using SMath 0.89. I have a plugin that will run with 0.89 but not 0.89.8 Beta without reprogramming. I expect the same for 0.90.
Ed
WroteI am unable to open these SMath files as they have been created using SMath 0.90 (Don't know where that comes from).
Version 0.89_8 beta will save the file and refere it as:
v.9.0.
WroteI am currently using SMath 0.89. I have a plugin that will run with 0.89 but not 0.89.8 Beta without reprogramming. I expect the same for 0.90.
I am not sure how is this going to work regarding plugins. If you made your own plugin, I suppose you should need to reprogame it yourself foer the new version - realy do not know. I hope that Andrey will make a plugins repository for different versions, or something like that. There would not be problems with the plugins Andrey will include in SMath. I am not sure what is going to be with the user made plugins - maybe some kind of freely upload/download repository of plugins. There are few of them - which I found very useful - posted here on the Forum. I hope that we would be able to use them in the future versions as well. Actually, this might depend mainly on the plugins creator.
Regards,
Radovan
Thanks for the reply.
I have a plugin I developed for 0.89. When I tried to link with the 0.89.8 Beta the function calls are different. Rather than reprogram I reverted back to 0.89 Stable.
I found that if I delete the area tag in the SMath file Noise_2 I'm able to read the 0.90 file.
I noticed that the functions Urw, Uir and Uopr from Noise_2 have different units nanoVolts, microVolts and Urw has some strange units with microVolts in it. So I think the problem is in the user function not SMath.
Haven't had a look at the others yet.
By the way I sent my plugin source to Andrey for consideration. If your interested its at
https://smath.com/wiki/GetFile.aspx?File=Programming%2fWizFunctions.zip
Ed

There are few other plugins posted by uni. Plugins for ODE solvers (rkfixed, Rkadapt), 3D potting, debuger of SMath functions etc. They are posted here for testing and made for 0.89_8 - I think. Just browse the Samples subforum if you are intersted in. Unfortunately, 0.89_8 is a bit different than 0.89 and these plugins must be used with installed SMath 0.89_8 (can not be used with Portable version).
Regards,
Radovan
-
Новые сообщения
-
Нет новых сообщений