MATLAB Answers

Using solve function to find the roots

31 views (last 30 days)
fert
fert on 18 Jan 2016
Commented: fert on 18 Jan 2016
syms x
y = 2*x*exp(-x)-sin(x)==0;
d=solve(y,x)
It gives the "zero" as the only value that makes the y zero. But the roots should be 0.8030 and 2.7923 (I have looked from ezplot). Why can't I find the roots with the solve function?

  0 Comments

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 18 Jan 2016
solve() can only find all solutions for polynomials. For non-linear functions, it will give a warning and find one numeric solution.
Since you need to switch to numeric solutions anyhow, use vpasolve() with initial guesses to select the range to find the solution over. vpasolve() will only find one solution at a time, but it will allow you to select the range to look in.

  3 Comments

fert
fert on 18 Jan 2016
It is not relevant with the former question, but do you think this code is right for comparing a function and its derivative:
clear all;clc
syms x
y = (log(1+x)+x.^2/2)/(1+x).^2
k=diff(y,x)
figure
ezplot(k)
hold on
ezplot(y)
Walter Roberson
Walter Roberson on 18 Jan 2016
Looks plausible, except that I would use
y = (log(1+x)+x.^2/2)./(1+x).^2
fert
fert on 18 Jan 2016
Thank you very much indeed.

Sign in to comment.

More Answers (0)

Sign in to answer this question.

Tags