-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFitting.en
34 lines (34 loc) · 1.09 KB
/
Fitting.en
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
>A:=[1,2;3,4]; b:=[5;6]; A\b
-4
4.5
>A:=normal(200,200); b:=sum(A); longest totalmax(abs(inv(A).b-1))
5.158096172408477e-013
>A:=redim(1:9,3,3); det(A)
0
>b:=[1,2,4]'; x:=fit(A,b); fraction(x)
1/6
1/3
0
>fraction(A.x-b)
-1/6
1/3
-1/6
% polyfit, polyval
>x:=[1:10]; y:=[5.7,6.5,6.7,6.4,7.7,7,8.6,9.3,9.3,13.2]; plot2d(x,y,>points);
>for i = 1 to 3; p:=polyfit(x,y,i); plot2d("polyval(p,x)",color=i+3,>add); end;
% modelfit (1. Beispiel)
>function fexp(x,[a,b,c]):=a*x+b*exp(c*x)
>p:=modelfit("fexp",[1,10,-1],x,y)
[1.12129, 6.76896, -0.292959]
>plot2d(x,y,>points); plot2d("fexp(x,p)",>add):
%image% Fitting-001.png
% modelfit (2. Beispiel)
>function model(x,p) := p[1]*cos(p[2]*x)+p[2]*sin(p[1]*x);
>xdata = [-2,-1.64,-1.33,-0.7,0,0.45,1.2,1.64,2.32,2.9];
>ydata = [0.699369,0.700462,0.695354,1.03905,1.97389,2.41143, ...
>1.91091,0.919576,-0.730975,-1.42001];
>p:=modelfit("model",[1.5,0.5],xdata,ydata)
[1.88185, 0.70023]
>plot2d(xdata,ydata,>points); plot2d("model(x,p)",>add):
%image% Fitting-002.png
>