필터 지우기
필터 지우기

Root finding and plotting

조회 수: 13 (최근 30일)
Mark
Mark 2021년 6월 17일
댓글: Star Strider 2021년 6월 18일
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

채택된 답변

Star Strider
Star Strider 2021년 6월 17일
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
Mark
Mark 2021년 6월 18일
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 2021년 6월 18일
I’ve definitely been there (although by now a few decades removed).
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Sulaymon Eshkabilov
Sulaymon Eshkabilov 2021년 6월 17일
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
Mark
Mark 2021년 6월 17일
Hi Sulaymon Eshkabilov,
Really thanks for your information!

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by