MATLAB How to use solve function in matlab in this case

  • Thread starter Thread starter oahsen
  • Start date Start date
  • Tags Tags
    Function Matlab
AI Thread Summary
The discussion focuses on finding the roots of a polynomial function defined by the equation exp(f(z)) = c, where c is a complex number. The user has derived f(z) by taking the natural logarithm, resulting in f(z) = log(c). They have implemented a function called expsolve that constructs the polynomial based on its coefficients and attempts to solve for the roots. The current implementation correctly forms the polynomial but struggles with finding the roots of the equation first - log(c) = 0. The user has attempted to use the solve function but encountered errors or nonsensical results. They seek guidance on how to correctly find the roots and are open to simpler methods for solving the problem. The suggested approach involves using symbolic variables and directly setting up the equation for solving.
oahsen
Messages
58
Reaction score
0
We are trying to find the roots of a function where exp(f(z)) = c. (where c is a complex number). Also f(z) is a polynomial function. The function will have the following format:
expsolve( [an an-1 …] , c ) where n is the degree of “z”.
For do this I took the natural logarithm of both sides and find f(z) = log(c). The code I have written so far is as follows;

function expsolve(v,c);
len=length(v)
temp=log(c);
syms z;
syms def;
syms first;
first=0;
for(a=1:len)
def=v(len-a+1)*(z^(a-1))
first=first+def
end
first
equ=first-log(c)

--------------------
now if I write expsolve([1 5 3], 4) for instance
until the first part it gives me the correct result (first=z^2+5*z+3)
however, I could not do the rest. how can I find the roots of first-log(c).

I tried to write different combination of :
solve('equ=0','z').
However, it gave my either an error or a illogical answer.

How can I proceed in this question. Besides the code I have written is there any simpler way to solve the question?
 
Physics news on Phys.org
Let's take it up from first. Write the code like this:
Code:
syms z;
eqn = first - log(c) == 0;
s = solve(eqn, z)
 

Similar threads

Back
Top