find the differences between two funtions

11 views (last 30 days)
Alex
Alex on 3 Mar 2019
Commented: madhan ravi on 6 Mar 2019
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

Answers (1)

Sreelakshmi S.B
Sreelakshmi S.B on 6 Mar 2019
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.

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!