Initial Conditions on the solve function?
Show older comments
Hi everyone,
I was wondering about the specifics of the 'solve' function within MATLAB. I have a series of non-linear functions (3 equations in 3 variables) that I am using 'solve' to find a solution for. However, there are multiple solutions that can work, and the 'solve' function returns the same one every time. Is there a way to specify initial conditions such that solve will return a different solution?
For example, I was playing with this the other day. Let's say I input the following:
syms x
solve('cos(x) = 0')
As we know, this has infinitely many solutions, but the solver will always return x = pi/2. Is there any way to have the solver output, for example, 3*pi/2?
Thanks in advance for all your help.
Answers (1)
Walter Roberson
on 5 Mar 2011
If you go more directly in to the toolbox, you can potentially provide a range.
feval(symengine, 'solve', sym('cos(x)'), sym('x=pi..3*pi'))
Or more compactly,
evalin(symengine, 'solve(cos(x),x=pi..3*pi)')
2 Comments
Andrew Yoon
on 5 Mar 2011
Walter Roberson
on 5 Mar 2011
In theory you could provide a system in inequalities that constrain the range of variables; you would provide that as a cell array first argument.
In practice, I don't know. I know that Maple does not handle inequalities well, but I don't know about MuPad.
What I would suggest trying is looping over the members of the set of solutions to solving over the first variable, solve()'ing each member for the appropriate range for the second variable. The symbolic function map() should be usable to do the loop, as in
evalin(symengine,'map(solve,solve(cos(x)+cos(y),x=0..2*pi),y=0..2*pi)')
Hypothetically it should work...
Categories
Find more on Common Operations in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!