find the differences between two funtions

조회 수: 4 (최근 30일)
Alex
Alex 2019년 3월 3일
댓글: madhan ravi 2019년 3월 6일
I have two functions as follows:
v=g*b/(2*pi*(1-nu)).*x.*(x.^2-y.^2)./(x.^2+y.^2).^2;
P=-g*b/(2*pi*(1-nu)).*(x./(x.^2+(y+zi).^2)-2.*x.*y*(y+zi)./(x.^2+(y+zi).^2).^2)
g=46e9;
b=0.2556e-9;
nu=0.33;
zi=0.155e-9;
y=1e-8;
x=2e-9:1e-10:2e-7;
I want to find that at what amount of x, the dfference between v and p is equal to 0.2

답변 (1개)

Sreelakshmi S.B
Sreelakshmi S.B 2019년 3월 6일
You can try the following code:
g=46e9;
b=0.2556e-9;
nu=0.33;
zi=0.155e-9;
y=1e-8;
x=2e-9:1e-10:2e-7;
v=@(x) g*b/(2*pi*(1-nu)).*x.*(x.^2-y.^2)./(x.^2+y.^2).^2;
P=@(x) -g*b/(2*pi*(1-nu)).*(x./(x.^2+(y+zi).^2)-2.*x.*y*(y+zi)./(x.^2+(y+zi).^2).^2);
%creating a function handle for calculating diff
diff = @(x) v(x) - P(x);
allZeros = [];
for x=2e-9:1e-10:2e-7
if(abs(round(diff(x),1))==0.2)
allZeros = [allZeros,x];
end
end
%allZeros will have all values of x for which diff is 0.2
However the values you've specified for x won't give you any values with diff. as 0.2 since the step size for x is too large.You can try observing where the diff is crossing over 0.2 and try reducing the step size.You can also plot the graph for 'P-v' and observe where it crosses 0.2.
  댓글 수: 1
madhan ravi
madhan ravi 2019년 3월 6일
Naming a variable diff is not recomended.

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

카테고리

Help CenterFile Exchange에서 Correlation and Convolution에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by