How to find the slope of the curve at x=0 and y=0

2 visualizzazioni (ultimi 30 giorni)
I wanted to find the slope of the curve, where is cross the x-axis and y-axis (there are four points), I am a beginner in Matlab, It would be very helpful if someone can help me.
Thanks in advance.
IV curve.jpg
  2 Commenti
Walter Roberson
Walter Roberson il 4 Ago 2019
Do you have the equations, and do you have the symbolic toolbox? If so then evaluate the derivatives at the appropriate points.

Accedi per commentare.

Risposte (1)

Star Strider
Star Strider il 4 Ago 2019
Modificato: Star Strider il 4 Ago 2019
Since you did not share your data, I created my own.
This should get you started:
x = linspace(-0.5, 1.5); % Create Data
y1 = 20*exp(0.8*x)-25; % Create Data
y2 = 15*exp(1.2*x)-35; % Create Data
dv = [-1 0 1]*1E-7;
zci = @(v) find(v(:).*circshift(v(:), [-1 0]) <= 0); % Returns Approximate Zero-Crossing Indices Of Argument Vector
y1zx = zci(y1); % Zero-Crossing Indices
dy1dx = gradient(y1,(x(2)-x(1))); % Numerical Derivative
y1y0x = interp1([y1(y1zx(1)-1),y1(y1zx(1)+1)],[x(y1zx(1)-1),x(y1zx(1)+1)],0); % Precise Zero-Crossing
dy1y0 = interp1([x(y1zx(1)-1),x(y1zx(1)+1)],[dy1dx(y1zx(1)-1),dy1dx(y1zx(1)+1)],y1y0x); % ‘y1’ Slope At y=0 ***
y2zx = zci(y2); % Zero-Crossing Indices
dy2dx = gradient(y2,(x(2)-x(1))); % Numerical Derivative
y2y0x = interp1([y2(y2zx(1)-1),y2(y2zx(1)+1)],[x(y2zx(1)-1),x(y2zx(1)+1)],0); % Precise Zero-Crossing
dy2y0 = interp1([x(y2zx(1)-1),x(y2zx(1)+1)],[dy2dx(y2zx(1)-1),dy2dx(y2zx(1)+1)],y2y0x); % ‘y2’ Slope At y=0 ***
x0 = find(x>=0, 1, 'first');
dy1x0 = interp1([x(x0-1),x(x0+1)],[dy1dx(x0-1),dy1dx(x0+1)],0); % ‘y1’ Slope At x=0 ***
dy2x0 = interp1([x(x0-1),x(x0+1)],[dy2dx(x0-1),dy2dx(x0+1)],0); % ‘y2’ Slope At x=0 ***
figure
plot(x, y1, x, y2)
grid
txtcely0 = sprintfc('\\leftarrow Slope = %.3f', [dy1y0, dy2y0]);
txtcelx0 = sprintfc('Slope = %.3f \\rightarrow', [dy1x0, dy2x0]);
text([y1y0x, y2y0x],[0 0], txtcely0, 'HorizontalAlignment','left', 'Rotation',-45)
text([0, 0],[y1(x0) y2(x0)], txtcelx0, 'HorizontalAlignment','right')
The slope results are signified by ‘***’ at the end of the comments.
EDIT — Added plot & text Calls.

Categorie

Scopri di più su Variables in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by