Using several variables with fsolve
2 次查看(过去 30 天)
显示 更早的评论
I have a 2x1 force matrix that I'd like to solve for 0. The problem right now is that it is completely made up of 6 variables and I'd like matlab to return solutions for 2 of the variables.
fsolve doesn't seem to be able to deal with this many variables.
For the matrix:
Ft=[3*Yc*k*exp(i*omega*t) - (23*L*k*theta*exp(i*omega*t))/20 - (5*L*Yc*m*omega^2*exp(i*omega*t))/2 ;
(443*L^2*k*theta*exp(i*omega*t))/400 - (23*L*Yc*k*exp(i*omega*t))/20 - (99*L^3*m*omega^2*theta*exp(i*omega*t))/160]
solve(Ft==0,Yc,theta)
I've even tried using:
solve(Ft(1,:)==0,Ft(2,:)==0,Yc,theta)
as well as just even:
solve(Ft(1,:)==0,Yc)
I would like to return solutions for Yc and theta.
The error I'm receiving for all methods is the following:
??? Error using ==> char
Conversion to char from logical is not possible.
Error in ==> solve>getEqns at 165
vc = char(v);
Error in ==> solve at 67
[eqns,vars] = getEqns(varargin{:});
0 个评论
回答(2 个)
Walter Roberson
2012-4-16
We are going to need to see your call to solve() and the equations you are passing in.
You would get the above error if you are passing in a logical value, which could (for example) happen if you use "==" in your equations.
The general solution for the matrix you show is Yc = 0, theta = 0. There are additional solutions such as Yc = 0, L = 0, theta = anything.
2 个评论
Walter Roberson
2012-4-17
Leave out the "== 0" . That is converting your inputs to boolean. Solving for the expressions being equal to zero is the default.
Sargondjani
2012-4-17
yes, walther is right (of course), you need to keep the syntax for fsolve:
YOur objective is: Ft=0, so pass as objective just 'Ft'.
BUT you have to write it as a function. First you have to specifiy the parameters, and then the function:
par1=...
par2=...
myfunction=@(var1,var2,...,var_last)[...;...];
on the ... in the [] you can write your orginal thingy, with the parameters and variables.
then you solve with fsolve:
fsolve(myfunction,[var1_0,var2_0,...var_last_0])
this is the format you should be using. BUT you have to understand that fsolve will only give 1 solution! in your case, there infinitely many solutions, so you need to work on that first (as the other poster was saying)
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Performance and Memory 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!