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?
John Williams answered .
2025-11-20
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.
years =
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.