# Should I trust solutions obtained for a nonlinear non-transcendental equation in matlab using 'fzero' function?

3 views (last 30 days)
Alireza Babaei on 16 Mar 2020
Commented: Walter Roberson on 18 Mar 2020
y = @(x)((10^-9)*x*(cosh(x)*sin(x)-sinh(x)*cos(x)) - ((10^-9)-1*(x^4)*(1+cosh(x)*cos(x))))
Suppose I have a kind of equation similar to the one above:
'y' is a function in variable 'x', it is a nonlinear, non-transcendental eqaution.
I have tried 'fzero', and I hae also plotted the function. So that plot gives me a shot regarding approximate location of the point whereas the function crosses y =0 line (corresponding x point is the answer). This is how I found the initial guess (eyeballing) and found following values for x:
0.149524, 1.875236, 4.694101
But wenenver I apply these numbers into the main equaiton to find the value of function at the mentioned points using 'subs' function in matlab, it is NOT equal to zero!!!!! (however we know value of function at the solution points should be equal to zero!!!!). Of course, using funciton 'round' yields zero. In short, I am a bit hessitant if my roots are correct or not.
Does anybody havea recommendation to find the roots? (logically snice I plot the function, I can estimate the first root should be pretty close to 0.15, and applying this initial guess into the 'fzero' function, yields 0.149524.) I don't know should trust it or not. (another reasin which makes me hesitant is the fact that physically the system obtaining such kind of nonlinear non-transcendental eqaution should have the first root close to 1.87).
Does anybody has a recommendation to solve such an enigma?
Thanks a lot

Show 1 older comment
Walter Roberson on 16 Mar 2020
Which release are you using? When I fzero(y,0.15) I get -1.87510406884409 not 0.149524
Alireza Babaei on 16 Mar 2020
Can you please run my code in the following:
clc
clear all
close all
syms x laL
L = 100e-3;
rm = input('rm = ')
rs = rm
x = linspace(0,10,100)
y1 = (rm*rs*(L^3)*laL*(cosh(laL)*sin(laL) - sinh(laL)*cos(laL)) - (rs*(L^3) - rm*(laL^4)*(1+cosh(laL)*cos(laL))))
y2 = (rm.*rs.*(L.^3).*x.*(cosh(x).*sin(x) - sinh(x).*cos(x)) - (rs.*(L^3) - rm.*(x.^4).*(1+cosh(x).*cos(x))))
xi = linspace(0,10,11)
for i = 1 : length(xi)
aa = vpasolve(y1 == 0, xi(i))
end
y3 = 1 + cos(x).*cosh(x)
subplot(2,1,1)
plot(x,y2,'LineWidth',2)
grid on
ylim([-.000001 .000001])
hold on l
plot(x,y3,'--r','LineWidth',2)
subplot(2,1,2)
plot(x,y2,'LineWidth',2)
grid on
ylim([-400 400])
hold on l
plot(x,y3,'--r','LineWidth',2)
hold off
Running this code, shows that the main function (presented in 'y1' or 'y2' has another root pretty much close to zero (almost 0.14)). I also plotted y function to see if there is really another root close to zero and it weems that it is. However practically it does not match with reality.
This is the thing making me confused.
On the other hand you say that your root even for initial guess around 0.15 is NOT 0.14
Walter Roberson on 17 Mar 2020
What value for rm?

Matt J on 16 Mar 2020
Edited: Matt J on 16 Mar 2020
fzero is a numerical root finder. One doesn't expect y(x) to be exactly zero at the roots that it finds, but it should be pretty close. One way to evaluate the result is to plot the function in a tight interval around the supposed root and see how close to zero it is compared to its neighbors. The three roots you've indicated look pretty good to me.
fun = @(x)((10^-9)*x*(cosh(x)*sin(x)-sinh(x)*cos(x)) - ((10^-9)-1*(x^4)*(1+cosh(x)*cos(x))));
[x1,y1]=fzero(fun,[0,0.2])
[x2,y2]=fzero(fun,[1,2])
[x3,y3]=fzero(fun,[4.2,5])
close all
figure;
fplot(fun, x1+[-1,1]*.0001);
hold on; plot(x1,y1,'ro','MarkerSize',6); hold off
figure;
fplot(fun, x2+[-1,1]*.0001);
hold on; plot(x2,y2,'ro','MarkerSize',6); hold off
figure;
fplot(fun, x3+[-1,1]*.0001);
hold on; plot(x3,y3,'ro','MarkerSize',6); hold off   Walter Roberson on 17 Mar 2020
syms laL
>> pretty(y1(laL))
4
laL (cos(laL) cosh(laL) + 1) laL (cos(laL) sinh(laL) - cosh(laL) sin(laL)) 1
----------------------------- - --------------------------------------------- - -------
1000 1000000000 1000000
>> pretty(y(laL))
4 laL (cos(laL) sinh(laL) - cosh(laL) sin(laL)) 1
laL (cos(laL) cosh(laL) + 1) - --------------------------------------------- - ----------
1000000000 1000000000
They are not the same equation. The y one has first term multiplied by 1000 and the third term divided by 1000 compared to the y1 equation.
Alireza Babaei on 17 Mar 2020
Yes, I'm doing with 'format long', ...
here is my abstract: I will go agead with both cases (root1 = 0.14 and root1 = 1.87) to see what is the response of the system and then decide about which one to nominate as the rirst root
Walter Roberson on 18 Mar 2020
You are working with two different equations. You need to figure out which of the two equations is right.
I suspect that when you built
y = @(x)((10^-9)*x*(cosh(x)*sin(x)-sinh(x)*cos(x)) - ((10^-9)-1*(x^4)*(1+cosh(x)*cos(x))))