FSolve - no solution found, last step ineffective

My function looks like this:
function F=Fn2(t)
global wn a g
F=(wn{1}^2)*a{1}(1,1)*sin(wn{1}*t)+(wn{2}^2)*a{2}(1,1)*sin(wn{2}*t)-g;
end
where wn, a, and g are defined in my main program. I call the function like this:
tlo=fsolve(@Fn2,1)
but fsolve can't seem to find a solution to the equation and is returning: "fsolve stopped because the last step was ineffective. However, the vector of function values is not near zero, as measured by the default value of the function tolerance."
"a" and "wn" are always real, and I've messed around with changing fsolve's x0 position. Any ideas why it's not working? Thanks in advance.

5 件のコメント

Matt J
Matt J 2013 年 11 月 27 日
編集済み: Matt J 2013 年 11 月 27 日
Perhaps there is no solution, for example, as would occur when
g > wn{1}^2*abs(a{1}(1,1)) + wn{2}^2*abs(a{2}(1,1))
Have you tested a case where the solution is known?
Matt J
Matt J 2013 年 11 月 27 日
編集済み: Matt J 2013 年 11 月 27 日
Incidentally, global variables are a discouraged method of passing fixed parameters to functions. You should really be doing this:
tlo=fsolve(@(t) Fn2(t,wn,a,g) ,1)
with Fn2 appropriately rewritten to accept (t,wn,a,g) as input arguments. See more info at http://www.mathworks.com/help/optim/ug/passing-extra-parameters.html
Eli
Eli 2013 年 11 月 28 日
Thanks Matt, I used Wolfram to find the numerical solution with the calculated values of wn and a, and came up with an answer, so the function should have some solution. I removed the global variables, but I still can't get it to work correctly.
Matt J
Matt J 2013 年 11 月 28 日
What are the values of wn,a, and g and what is the corresponding solution t?
Eli
Eli 2013 年 11 月 28 日
編集済み: Eli 2013 年 11 月 28 日
wn{1}=4.628
a{1}(1,1)=-2.92
wn{2}=39.01
a{2}(1,1)=-.0049
g=32.17
This should yield tlo=0.766. I also plotted F exactly as it appears in the function Fn2 and can see that it clearly crosses the X axis around 0.766, so there's either a problem with how Fn2 is receiving input or with how I have fsolve set up

サインインしてコメントする。

 採用された回答

Matt J
Matt J 2013 年 11 月 28 日

1 投票

FSOLVE can do it, but it has a rather narrow radius of capture around the desired tlo, roughly between 0.55 and .79
>> Fn2=@(t) (wn{1}^2)*a{1}(1,1)*sin(wn{1}*t)+(wn{2}^2)*a{2}(1,1)*sin(wn{2}*t)-g;
>> [tlo,fval] = fsolve(Fn2,.6,optimset('Display','none'))
tlo =
0.7667
fval =
7.1054e-15

3 件のコメント

Matt J
Matt J 2013 年 11 月 28 日
There are also other solutions, of course,
>> [tlo,fval] = fsolve(Fn2,.51,optimset('Display','none'))
tlo =
1.2644
fval =
-3.5527e-14
Matt J
Matt J 2013 年 11 月 28 日
FZERO has a fair bit larger radius of capture, roughly between .4 and 1.01
>> [tlo,fval] = fzero(Fn2,1)
tlo =
0.7667
fval =
7.1054e-15
Eli
Eli 2013 年 11 月 28 日
Thanks again Matt, it seems like FZERO is the way to go because I won't always have an estimate about where tlo will be.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

質問済み:

Eli
2013 年 11 月 27 日

編集済み:

Eli
2013 年 11 月 28 日

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by