How can I plot a symbolic function or determine a finite and real starting guess for fzero?
1 次查看(过去 30 天)
显示 更早的评论
Hello,
I have a very long and somewhat complicated complex function that I need to find the roots of. It is a function of "s", which is imaginary, and which I had to define as a symbol in order to work through previous steps and get the function (Functionofs). For those interested in the background math, I am trying to solve the characteristic equation from a determinant of a 4x4 matrix made from a transfer function made from the equations of motion of a beam. When I try starting guesses that I think would make sense using the fzero command, I keep getting the error "Function value at starting guess must be finite and real." I have tried the following:
1) Tried substituting values using subs(Functionofs,s,1*i) to see if I could happen upon something that would work. It just finished (after several minutes) and gave me an extremely long (output truncated) expression with fractions, etc. Does not seem to be of any use. I used simplify(ans) and got it down to a manageable (sort of) size, but it is still a symbol- can I convert this back to a decimal number or expression somehow?
2) Tried to plot Functionofs, but received an error that SYM could not be converted to DOUBLE to plot.
Does anyone have any ideas on what else I could try or how to get around these errors? I have not found a way to convert a symbol to a decimal number- is there one?
Thank you! It's a pretty interesting problem! -Kaitlin
0 个评论
采纳的回答
Matt Fig
2012-9-5
编辑:Matt Fig
2012-9-5
If you have a function of one variable, you can use my newtzero to try to find some roots. You will have to convert to a function handle first.
For example:
syms s
f = s.^(2*cos(s)) -s.^3 - sin(s)+1; % Say this is your function.
% Now to find the roots.
G = matlabFunction(f); % Convert to func handle.
newtzero(G) % Can use no or real or imaginary guess.
ans =
0.4192 - 0.7229i
0.4192 + 0.7229i
1.0584
-0.4221 - 1.2644i
-0.4221 + 1.2644i
-0.2607 - 1.8053i
1.7397 - 1.5257i
-4.5851 - 0.7860i
As far as the plotting goes, just use the function handle returned in G above.
4 个评论
Matt Fig
2012-9-6
Hello,
NEWTZERO, like all other numerical root finders, has limitations. It uses Newton's method with a vector of initial guesses (to take advantage of MATLAB's vectorization). I wrote it when I was in grad school because I needed to find complex roots and was tired of having to plot a complex function to get the initial guess with FZERO. If you are getting many roots, your function may be periodic or just have many roots. Without seeing the function I can't tell. It is up to you to check that indeed the roots returned are zeros and to interpret their physical meaning.
An empty return just means none of the initial guesses converged. You can play around with the tolerance if you are sure there is a root somewhere that NEWTZERO isn't finding. Any guess that evaluates to a finite, non-nan value is valid.
Good luck!
更多回答(1 个)
Walter Roberson
2012-9-5
Use vpa() to reduce the constant expressions.
Use matlabFunction() to convert a symbolic expression to a function handle.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Symbolic Math Toolbox 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!