Community Tip - You can subscribe to a forum, label or individual post and receive email notifications when someone posts a new topic or reply. Learn more! X
Hi,
I was wondering if there was any way to use find given a set of differential equation. Here is a (simple) example : charge of an RC system.
input voltage, and capacitor value are known. I want to find the resistor value such that, after a given time Tx, the capacitor voltage is Vx.
Obviously, this example is simple enough to solve manually, but could this be applied to much more complex systems where manual solving is not an option.
Solved! Go to Solution.
The old command line solvers can be incorporated into programs, then used in solve blocks.
We must use Odesolve.
I will try to solve it!
Doesn't odesolve need a value for R ?
If it was possible to solve the ODE symbolically, then use find the the value of R, that would do the trick for this particular example, but symbolic solve sin't always an option, especially in areas where there are lots of ifs in the equations.
The old command line solvers can be incorporated into programs, then used in solve blocks.
That's a great solution ! Thank you very much !
Fred, I just had a look a your sheet again to see whats the problem because it should work OK the way you had set it up. I think I found the cause for the wrong value for R. Its the match() function and a simple precision problem which can be coped with in several ways:
1) Decrease TOL to something like 10^-10
2) Replace the calculation line for dx to take the mean of all indices wich match would return
3) Omit the match function completely and use some sort of interpolation (linear should be good enough here)
BTW, any specific reason you had set up your ODE using the charge function instead of the voltage function directly? A clever idea to use the constant R as second "function" to solve for. Incidentally we can do without that trick if we resort to a small program which creates the vector D for rxfixed on the fly. See attached file.
Personally I still prefer the odesolve approach but think its a pity we don't have any control anymore in Prime as of the algorithm used.
Here is a different approach using two solve blocks, one with odesolve, the second with find.
I get a different value for the resistor (785.57 ohm, compared to Fred's 710.94 ohm) , though, haven't checked why.
EDIT: Just used the easy to find exact solution of the ODE and found the correct value for the restistor again with 785.57 ohm! Not sure whats the problem in Fred's sheet.
EDIT2: Found the problem in Fred's approach. It was a simple precison problem because of the rather small time values used. Match() would find a couple of matches within the given tolerance and the first one of this list is not the best one. See my other reply to Fred's post for details and solution.
Interesting, your approach is much closer to what I "instinctively" wanted to do, except that your syntax works !
Both solutions are really interesting, I will have to spend some time understanding in details how all that works, but this does exactly what I was looking for.
Many thanks to both of you !
Adrien Thurin wrote:
Interesting, your approach is much closer to what I "instinctively" wanted to do, except that your syntax works !
Yes, you approach was quit intuitive but unfortunately thats no the way Prime works.
The points (apart from using the boolean = instead of the assignment := for equations) to consider are:
One thing concerning odesolve vs. command line solver. Odesolve in a solve block might be more attractive because it uses a more intuitive syntax. The command line solvers might have advantages if used inside of programs. In Prime we have one additional reason for using the command line solver because here we have control over the algorithm used (we have a handful of different solvers to chose from). In Mathcad we could chose different algorithms for odesolve, too, but in Prime we have the "i do it for you" appraoch (which admittedly works pretty well most of the time).
The results of both approaches are slightly different. The command line solvers return a matrix of scalars. First column are t-values, second column function values of first solved for function, etc. If you need a true function with values inbetween, you have to use some kind of interpolation as I did in my third way to avoid the precision problem in Fred's sheet. The result of odesolve is pretty much the same, but here you don't a fubnction name as result, not the discrete values themselves. Internally this is represented by the very same marix values coupled with an automatic interpolation but the user has no access to those matrix values and does not know which kind of interpolation is applied. Again that mechanism works pretty well but sometimes users have the urge for a bit more control over the situation and use the command line solvers for that reason.
Thanks for the explanation. I will keep that in mind in the future !