How to use solve function in matlab in this case

In summary, the conversation discusses finding the roots of a function where exp(f(z)) = c, with c being a complex number. The function is in the format expsolve([an an-1 …] , c) and f(z) is a polynomial function. To solve this, the natural logarithm of both sides is taken and the resulting equation is solved for z. The code provided uses a for loop to calculate the first part of the equation, but the rest of the code is still being worked on. The speaker is looking for a simpler way to solve the problem and asks for assistance in finding the roots of the function.
  • #1
oahsen
59
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
  • #2
Let's take it up from first. Write the code like this:
Code:
syms z;
eqn = first - log(c) == 0;
s = solve(eqn, z)
 

1. How do I use the solve function in Matlab?

The solve function in Matlab allows you to solve equations or systems of equations. To use it, simply type "solve" followed by the equation or system of equations you want to solve, and then include the variable you want to solve for. For example, if you want to solve the equation x + 2 = 5 for x, you would type "solve(x + 2 == 5, x)".

2. What type of equations can be solved using the solve function in Matlab?

The solve function in Matlab can be used to solve linear, polynomial, and transcendental equations. It can also solve systems of equations, which are equations with multiple variables.

3. How do I solve for multiple variables using the solve function in Matlab?

To solve for multiple variables, you can use the same syntax as solving for a single variable. Simply include all of the variables you want to solve for in the function. For example, if you want to solve the system of equations x + y = 5 and 2x + 3y = 10 for both x and y, you would type "solve(x + y == 5, 2x + 3y == 10, x, y)".

4. Can the solve function in Matlab handle complex numbers?

Yes, the solve function in Matlab can handle complex numbers. You can use the "i" symbol to represent the imaginary unit, and the function will return both real and imaginary solutions.

5. Is there a way to check if the solution returned by the solve function in Matlab is correct?

Yes, you can check the solution returned by the solve function by plugging it back into the original equation and seeing if it satisfies the equation. You can also use the "isAlways" function in Matlab to verify the solution analytically.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
Back
Top