Download as pdf or txt
Download as pdf or txt
You are on page 1of 1

1 X [1.190984579 1.15776987 1.12455516 1.096085409 1 . 0 6 7 6 1 5 6 5 8...

LJ
2 1.034400949 1.003558719 0.975088968 0.944246738 0.911032028...
3 0.877817319 0.846975089 0.825622776];
4 Y [0.526690391 0.517200474 0.519572954 0.533807829 0.550415184...
5 0.56227758 0.552787663 0.536180308 0.521945433 0.521945433...
6 0.524317912 0.517200474 0.495848161];
7
8 n=6; % polynomial fit
9 range = 5 0;
10 figure
11 scatter(x,y),hold on
12 [p,~,mu] = polyfit(x,y,n);
13 % Plot the fit with the data
14 xfit = linspace(min(x),max(x),range);
15 yfit = polyval(p,xfit,[],mu);
16 plot(xfit,yfit,'r'),xlafcel('x'), ylafcel('y')
17
18 % Tangent line
19 indexX = input([ 1 Enter index in the range ',num23tr([l length(xfit)]),': 1 ]);
20 _
dydx approx = diff(yfit)./diff(xfit);
21 _ _
Tangent line adjust = 0.05;
22 - _ _
X = [xfit(indexX) Tangent line adjust _ _
xfit(indexX)+Tangent line adjust];
23 _ _ -
tangent line = yfit(indexX) + dydx approx(indexX)*(X xfit(indexX));
24 plot(X,tangent line, * b')
25

You might also like