How to draw the tangent line on a curve
24 ビュー (過去 30 日間)
古いコメントを表示
I would like to plot the tangent of the curve I (V) and find the slope and then the intersection of the tangent with the x axis (V0).
I am attaching the curve data (I, U) and a summary image of what I am looking for. Thank you in advance for your help
0 件のコメント
採用された回答
Star Strider
2021 年 6 月 29 日
Try this —
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/668953/Tan.xlsx')
I = T1.I;
V = T1.V;
dI = gradient(I);
dV = gradient(V);
Vi = 1.3; % Choose Voltage Value To Calculate Slope
Ii = interp1(V, I, Vi);
dVi = interp1(V, dV, Vi)
dIi = interp1(V, dI, Vi)
Slope = dIi/dVi
YIntercept = Ii - Slope * Vi
XIntercept = -YIntercept / Slope
figure
plot(V,I)
hold on
plot(Vi, Ii, 'p')
plot(xlim, xlim*Slope+YIntercept, '-r')
plot(XIntercept, 0, 'sr')
hold off
grid
xlabel('V')
ylabel('I')
text(Vi, Ii, sprintf('$I = %.3f \\times V %+.3f \\rightarrow \\ $', Slope, YIntercept), 'Horiz','right', 'Vert','middle', 'Interpreter','latex')
text(XIntercept, 0, sprintf('$%.4f V \\downarrow $', XIntercept), 'Horiz','right', 'Vert','bottom', 'Interpreter','latex')
ylim([0 max(ylim)])
.
6 件のコメント
Sharatkumar Kondikoppa
2022 年 1 月 23 日
In your code you have taken Vi =1.3 , did you choose randomly or took a mean value ? Can you explain me.
Or can I choose any value ?
Star Strider
2022 年 1 月 23 日
I chose that value for ‘Vi’ since although the exact point was not stated, it was certainly implied in the ‘image001.png’ plot.
So ‘Vi’ can be any point in the curve.