Root finding and plotting

27 views (last 30 days)
Mark
Mark on 17 Jun 2021
Commented: Star Strider on 18 Jun 2021
How do I find the three roots of " f "
I got the plot of " f." And because the " f " and X asis has three intersections, it would have three roots.
I would like to know how to find the three roots at the same time and plot the three roots on my original plot.
Below is my coding.
Thank you very much!!
clc
clear
format long
v=0.3;
E=209e+3;
G=E/(2*(1+v));
q=-1;
h=15;
D=(E*h^3)/(12*(1-v^2));
I=(h^3)/12;
a=600;b=2400;
n =3;
[T1, T2] = meshgrid(1:2:n);
mn = [T1(:), T2(:)]
syms x y
x_value=301;
y_value=0:1:2400;
len=length(mn);
amn=zeros(1,len);
for i=1:len
m=mn(i,1);
n=mn(i,2);
amn(i)=(16*q/(m*n*D*pi^6))*(1/((m/a)^2+(n/b)^2)^2);
end
wmn=sym(zeros(1,len));
wxx=sym(zeros(1,len));
wyy=sym(zeros(1,len));
for i=1:len
m=mn(i,1);
n=mn(i,2);
wmn(i)=amn(i).*((sin(m.*pi.*x./a)).*(sin(n.*pi.*y./b)));
wxx(i)=diff(wmn(i),x,2);
wyy(i)=diff(wmn(i),y,2);
end
combine_wxx=sum(wxx);
combine_wyy=sum(wyy);
My=-D*(combine_wyy+v*combine_wxx);
Differentiation_My=diff(My,y,1)
f=subs(Differentiation_My,x,301)
%fsolve(f,500)
Differentiation_My_value=double(subs(Differentiation_My,{x,y},{x_value,y_value}));
plot(Differentiation_My_value)
grid on

Accepted Answer

Star Strider
Star Strider on 17 Jun 2021
One way is to search for the indices nearest the zero-crossings, then interpolate (if necessary, to get more exact values) —
format long g
v=0.3;
E=209e+3;
G=E/(2*(1+v));
q=-1;
h=15;
D=(E*h^3)/(12*(1-v^2));
I=(h^3)/12;
a=600;b=2400;
n =3;
[T1, T2] = meshgrid(1:2:n);
mn = [T1(:), T2(:)]
mn = 4×2
1 1 1 3 3 1 3 3
syms x y
x_value=301;
y_value=0:1:2400;
len=length(mn);
amn=zeros(1,len);
for i=1:len
m=mn(i,1);
n=mn(i,2);
amn(i)=(16*q/(m*n*D*pi^6))*(1/((m/a)^2+(n/b)^2)^2);
end
wmn=sym(zeros(1,len));
wxx=sym(zeros(1,len));
wyy=sym(zeros(1,len));
for i=1:len
m=mn(i,1);
n=mn(i,2);
wmn(i)=amn(i).*((sin(m.*pi.*x./a)).*(sin(n.*pi.*y./b)));
wxx(i)=diff(wmn(i),x,2);
wyy(i)=diff(wmn(i),y,2);
end
combine_wxx=sum(wxx);
combine_wyy=sum(wyy);
My=-D*(combine_wyy+v*combine_wxx);
Differentiation_My=diff(My,y,1)
Differentiation_My = 
f=subs(Differentiation_My,x,301)
f = 
%fsolve(f,500)
Differentiation_My_value=double(subs(Differentiation_My,{x,y},{x_value,y_value}));
zxi = find(diff(sign(Differentiation_My_value))) % Zero-Crossing Indices
zxi = 1×4
583 1200 1201 1818
for k = 1:numel(zxi)
idxrng = max(zxi(k)-2,1):min(zxi(k)+2,numel(Differentiation_My_value)); % Index Range For Interpolation
zc(k) = interp1(Differentiation_My_value(idxrng),idxrng,0); % Interpolate
end
Zero_Crossings = zc
Zero_Crossings = 1×4
583.376183230044 1201 1201 1818.62381676996
plot(Differentiation_My_value)
hold on
plot(zc, zeros(size(zc)), 'rs')
hold off
grid on
To plot it against an ‘x’ vector instead of the indices, the ‘zc’ calculation becomes:
% zc(k) = interp1(Differentiation_My_value(idxrng), x(idxrng), 0);
I commented it here because it would otherwise execute in the online Run feature, and throw an error.
.
  8 Comments
Mark
Mark on 18 Jun 2021
Sounds Great! It so nice of you!! I am a matlab beginner user and sometimes I may meet problems when I do the simulation work for my graduate school study. I will try my best to deal with it by myshelf at first and if I still cannot deal with it I will let you know my questions. Really thanks a lot : )
Star Strider
Star Strider on 18 Jun 2021
I’ve definitely been there (although by now a few decades removed).
As always, my pleasure!

Sign in to comment.

More Answers (1)

Sulaymon Eshkabilov
Sulaymon Eshkabilov on 17 Jun 2021
There are a couple of ways to find roots of this eqn:
(1) ginput() --> graphical method, e.g.:
[Roots, y] = ginput(3) % click on three crossing points
(2) fsolve()
  1 Comment
Mark
Mark on 17 Jun 2021
Hi Sulaymon Eshkabilov,
Really thanks for your information!

Sign in to comment.

Tags

Products


Release

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!