x=0:0.1:2;
f=2*x-3 + randn(size(x));
plot(x,f)
plot(x,f,'*')
f=2*x-3 + 0.5*randn(size(x));
plot(x,f,'*')
fi0=@(x)ones(size(x));
fi1=@(x)x;
A=[fi0(x'), f1(x')]
{Undefined function or variable 'f1'.}
A=[fi0(x'), fi1(x')]
A =
1.0000 0
1.0000 0.1000
1.0000 0.2000
1.0000 0.3000
1.0000 0.4000
1.0000 0.5000
1.0000 0.6000
1.0000 0.7000
1.0000 0.8000
1.0000 0.9000
1.0000 1.0000
1.0000 1.1000
1.0000 1.2000
1.0000 1.3000
1.0000 1.4000
1.0000 1.5000
1.0000 1.6000
1.0000 1.7000
1.0000 1.8000
1.0000 1.9000
1.0000 2.0000
b=f';
c=inv(A'*A)*A'*b
c =
-2.8192
1.7677
plot(x,c(2)*x+c(1),x,f,'*')
f=2*x-3 + 0.1*randn(size(x));
plot(x,f,'*')
c=inv(A'*A)*A'*b
c =
-2.8192
1.7677
b=f';
c=inv(A'*A)*A'*b
c =
-2.9945
1.9984
plot(x,c(2)*x+c(1),x,f,'*')
fi2=@(x)abs(x-1.2);
f=2*fi0(x)-fi1(x)+3*fi2(x)+0.5*randn(size(x));
plot(x,f,'*')
A=[fi0(x'), fi1(x'), fi2(x')]
A =
1.0000 0 1.2000
1.0000 0.1000 1.1000
1.0000 0.2000 1.0000
1.0000 0.3000 0.9000
1.0000 0.4000 0.8000
1.0000 0.5000 0.7000
1.0000 0.6000 0.6000
1.0000 0.7000 0.5000
1.0000 0.8000 0.4000
1.0000 0.9000 0.3000
1.0000 1.0000 0.2000
1.0000 1.1000 0.1000
1.0000 1.2000 0
1.0000 1.3000 0.1000
1.0000 1.4000 0.2000
1.0000 1.5000 0.3000
1.0000 1.6000 0.4000
1.0000 1.7000 0.5000
1.0000 1.8000 0.6000
1.0000 1.9000 0.7000
1.0000 2.0000 0.8000
b=f';
c=inv(A'*A)*A'*b
c =
1.3515
-0.7232
3.8004
plot(x,c(1)*fi0(x)+c(2)*fi1(x)+c(3)*fi2(x),x,f,'*')
f=2*fi0(x)-fi1(x)+3*fi2(x)+0.1*randn(size(x));
b=f';
c=inv(A'*A)*A'*b
c =
1.9937
-1.0176
3.0166
plot(x,c(1)*fi0(x)+c(2)*fi1(x)+c(3)*fi2(x),x,f,'*')
pinv(A)*b
ans =
1.9937
-1.0176
3.0166
plot(x,c(1)*fi0(x)+c(2)*fi1(x)+c(3)*fi2(x),x,f,'*')
c
c =
1.9937
-1.0176
3.0166
diag(c)
ans =
1.9937 0 0
0 -1.0176 0
0 0 3.0166
diag(c,-1)
ans =
0 0 0 0
1.9937 0 0 0
0 -1.0176 0 0
0 0 3.0166 0
diag(c,1)
ans =
0 1.9937 0 0
0 0 -1.0176 0
0 0 0 3.0166
0 0 0 0
help lim
lim not found.
Use the Help browser search field to search the documentation, or
type "help help" for help command options, such as help for methods.
help limit
--- help for sym/limit ---
limit Limit of an expression.
limit(F,x,a) takes the limit of the symbolic expression F as x -> a.
limit(F,a) uses symvar(F) as the independent variable.
limit(F) uses a = 0 as the limit point.
limit(F,x,a,'right') or limit(F,x,a,'left') specify the direction
of a one-sided limit.
Examples:
syms x a t h;
limit(sin(x)/x) returns 1
limit((x-2)/(x^2-4),2) returns 1/4
limit((1+2*t/x)^(3*x),x,inf) returns exp(6*t)
limit(1/x,x,0,'right') returns inf
limit(1/x,x,0,'left') returns -inf
limit((sin(x+h)-sin(x))/h,h,0) returns cos(x)
v = [(1 + a/x)^x, exp(-x)];
limit(v,x,inf,'left') returns [exp(a), 0]
Reference page for sym/limit
syms x n
limit((1+1/n)^n,n,inf)
ans =
exp(1)
limit((1+x/n)^n,n,inf)
ans =
exp(x)
limit((1+1/n)^n)
ans =
1
limit(sin(x)/x)
ans =
1
limit(sin(x)/x,x,0)
ans =
1
format long
(1+1/10)^10
ans =
2.593742460100002
exp(1)
ans =
2.718281828459046
clear n
n=100;
(1+1/n)^n
ans =
2.704813829421528
n=1000;
(1+1/n)^n
ans =
2.716923932235594
ans-exp(1)
ans =
-0.001357896223452
for k=1:20, n=10*n;(1+1/n)^n-exp(1),pause, end
ans =
-1.359016341200281e-04
ans =
-1.359126674804756e-05
ans =
-1.359363292152693e-06
ans =
-1.343269637743560e-07
ans =
-3.011168780986395e-08
ans =
2.235525147220585e-07
ans =
2.247757420192897e-07
ans =
2.248980646157861e-07
ans =
2.416675781922173e-04
ans =
-0.002171794372145
ans =
-0.002171794372023
ans =
0.316753378090216
ans =
-1.718281828459046
ans =
-1.718281828459046
ans =
-1.718281828459046
ans =
-1.718281828459046
ans =
-1.718281828459046
ans =
-1.718281828459046
ans =
-1.718281828459046
ans =
-1.718281828459046
1-exp(1)
ans =
-1.718281828459046
n=10;
for k=1:20, n=10*n;(1+1/n)^n,pause, end
ans =
2.704813829421528
ans =
2.716923932235594
ans =
2.718145926824926
ans =
2.718268237192297
ans =
2.718280469095753
ans =
2.718281694132082
ans =
2.718281798347358
ans =
2.718282052011560
ans =
2.718282053234788
ans =
2.718282053357110
ans =
2.718523496037238
ans =
2.716110034086901
ans =
2.716110034087023
ans =
3.035035206549262
ans =
1
ans =
1
ans =
1
ans =
1
ans =
1
ans =
1
n
n =
1.000000000000000e+21
1+1/n
ans =
1
s=1;
f=1;
for k=1:20, f=f*k; s=s+1/f;[k exp(1)-s],pause, end
ans =
1.000000000000000 0.718281828459046
ans =
2.000000000000000 0.218281828459046
ans =
3.000000000000000 0.051615161792379
ans =
4.000000000000000 0.009948495125712
ans =
5.000000000000000 0.001615161792379
ans =
6.000000000000000 0.000226272903490
ans =
7.000000000000000 0.000027860205077
ans =
8.000000000000000 0.000003058617775
ans =
9.000000000000000 0.000000302885853
ans =
10.000000000000000 0.000000027312661
ans =
11.000000000000000 0.000000002260553
ans =
12.000000000000000 0.000000000172877
ans =
13.000000000000000 0.000000000012286
ans =
14.000000000000000 0.000000000000815
ans =
15.000000000000000 0.000000000000051
ans =
16.000000000000000 0.000000000000003
ans =
17 0
ans =
18 0
ans =
19 0
ans =
20 0
factorial(17)
ans =
3.556874280960000e+14
1+1/ans
ans =
1.000000000000003
factorial(18)
ans =
6.402373705728000e+15
1+1/ans
ans =
1.000000000000000
clear all
syms x t
diff(sin(x)*cos(x))
ans =
cos(x)^2 - sin(x)^2
diff(sin(x)*cos(x),t)
ans =
0
diff(sin(x)*cos(x),2)
ans =
-4*cos(x)*sin(x)
taylortool
diary off