Solving simultaneous equations numerically
4 views (last 30 days)
Show older comments
John Smith
on 16 Oct 2014
Commented: Mohammad Abouali
on 21 Oct 2014
I have two equations that need to be solved numerically, I can't write out the equations explicitly but they are both of the form:
x = \sum_{i=1}^N (a-(b_i)x)/((a-(b_i)x)^2+q^2y^2)
All the parameters other than x and y are fixed in this equation. Both my equations are of similar forms but I'm not sure what is the best way to solve this numerically in MATLAB as these equations involve the summation and I have never dealt with this kind of equation in MATLAB before.
p.s. sorry for the mess but I hope the form of the equation is clear enough. Thanks.
0 Comments
Accepted Answer
Mohammad Abouali
on 16 Oct 2014
Edited: Mohammad Abouali
on 16 Oct 2014
Here is what you need to do
1) write a function like this:
funX=@(x,y,N,a,q) sum((a-b.*x)./((a-b.*x).^2+q.^2.*y.^2));
funY=@(x,y,N,a,q) whatever the equation is for Y
fun1=@(x,y,N,a,q) ([funX(x,y,N,a,q); ...
funY(x,y,N,a,q)]);
Note that fun1 is the right-hand-side of your equation. (correct it if I miss code it)
2) use "fsolve" or another method of your choice to solve it as follow
a= 'the value you want'
N= 'the value you want'
q= 'the value you want'
%Your first equation is x=FunX based on your question.
%Assuming your second equation is also of the form y=FunY
%P=[x;y] so P(1)=x and P(2)=y;
fun2=@(P) (P-fun1(P(1),P(2),N,a,q))
InitialGuess=[x0;y0];
fsolve(fun2,InitialGuess)
This way, you can change N, a, q programitically
20 Comments
More Answers (1)
Roger Stafford
on 16 Oct 2014
Edited: Roger Stafford
on 16 Oct 2014
It doesn't matter that your two equations involve an extended summation. You can still create a function that generates these sums which you can use with the Optimization Toolbox function, 'fsolve'. You will, however, need to also furnish a guess or estimate to start the search for a solution. See:
http://www.mathworks.com/help/optim/ug/fsolve.html
5 Comments
John D'Errico
on 20 Oct 2014
Edited: John D'Errico
on 20 Oct 2014
No. I understood exactly what you were asking. It did not come out wrong.
This means they are unknowns, symbolic variables. You are asking for a symbolic solution. Just because something is an unknown does not mean that you need to solve for it, or that you can solve for it!
A numerical solver (fsolve, lsqnonlin, fmincon, or fzero for a few examples) CANNOT have unknown symbolic variables in the problem. It is no longer a numerical problem, but a symbolic one, not in their domain.
If you really want to see how the solution varies as a function of these variables, the best you can do with a numerical solver is to substitute in some values for those parameters, THEN you can solve the problem using a numerical solver, and I suppose plot the result as a function of those parameters you have substituted.
If however, you insist on seeing an analytical solution in terms of those unknowns, then you need to use a tool that can handle symbolic computations.
There is no mistake here. I do understand what you are asking.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!