FSolve with Matrix Input
19 次查看(过去 30 天)
显示 更早的评论
fsolve is really confusing me. All the examples find show a system of equations being input in character form. Mine are in matrix form. As I understand it x0 is meant to define a boundary condition for solving the system, so that the solver doesn't fly off into infinity and crash if some of the equations are bad. I don't understand the point of function f though. Shouldn't this be the array which contains the system of equations to be solved?
I've seen several examples of fsolve in matlab, but can't seem to find any that show how to pass parameters in matrix form.
In this example I'm using only two equations but in practice I actually have hundreds to solve simultaneously so it's a rather large matrix.
Thanks!
Here is my code.
[A,b] = equationsToMatrix(eq1,eq2)
X0 = [0 0]
fsolve([A,b], X0)
Here is the output
eq1 = - sx - sy/2 == 5
eq2 = - (3*sx)/2 - (3*sy)/2 == 9
A =
[ -1, -1/2]
[ -3/2, -3/2]
b =
5
9
X0 =
0 0
Error using lsqfcnchk (line 109)
If FUN is a MATLAB object, it must have an feval method.
Error in fsolve (line 198)
funfcn = lsqfcnchk(FUN,'fsolve',length(varargin),funValCheck,gradflag);
Error in SolveTesting (line 70)
fsolve([A,b], X0)
0 个评论
采纳的回答
Yatin
2013-10-18
Hi,
I see that your equations are linear. You can therefore use matrix left division ("\") for better speed and accuracy instead of " fsolve ". So as per the above case:
A = [-1, -1/2; -3/2,-3/2];
b = [5;9];|
then
x = A\b;
This should give you your desired result.
6 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Calculus 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!