matlab第一章
a=3
a =
3
complex(3,4)
ans =
3.0000 + 4.0000i
%Example 1.1
x=0.1;
a=0.5;
y=sqrt(abs(exp(-pi*x)-sin(x)/cosh(a)-log(x+a)))
y =
1.0736
The file naming convention is the same as that for variable names:
- It must start with upper or lower case letter followed by up to 62 contiguous alphanumeric charactersand the undercore character
- No blank spaces are allowed in filenames
crtl + i:向左缩进
% 符号运算
syms a b
d = 4.2;
f = 11.92*exp(-a^2)+b/d
f =
(5*b)/21 + (298*exp(-a^2))/25
f1 = vpa(f,5)
f1 =
0.2381*b + 11.92*exp(-1.0*a^2)
y = vpa('factorial(32) - exp(100)', 100)
Warning: Support of character vectors that are not valid variable names or define a number will be removed in a future release. To create symbolic expressions, first create symbolic variables and then use operations on them.
> In vpa (line 49)
y =
-26881171155030517550432725348582123713611118.77374192241519160861528028703490956491415887109721984571
% 微分
syms b t
dt = diff(b*cos(b*t),t,1)
db = diff(b*cos(b*t),b,1)
dt =
-b^2*sin(b*t)
db =
cos(b*t) - b*t*sin(b*t)
% 积分
it = int(dt,t)
ib = int(db,b)
it =
b*cos(b*t)
ib =
b*cos(b*t)
% 求极限
syms y x
Lim = limit((1+y/x)^x,x,inf)
Lim =
exp(y)
% taylor展开
syms x tho
Tay = taylor(cos(x), tho)
Tay =
cos(x)
% inverse laplace transform
syms s t z r
f = ilaplace(1/(s^2+2*z*s+1),s,t)
f =
(exp(-t*z)*sinh(t*(z^2 - 1)^(1/2)))/(z^2 - 1)^(1/2)
[Nu De] = numden(f)
Nu =
exp(-t*z)*sinh(t*(z^2 - 1)^(1/2))
De =
(z^2 - 1)^(1/2)
fNu = subs(Nu,(z^2-1)^(1/2), i*r);
fDe = subs(De,(z^2-1)^(1/2), i*r);
pretty(simplify(fNu/fDe))
exp(-t z) sin(r t)
------------------
r
% Example 1.3 determination of curvature
syms t a b
x = 2*b*cos(t)+b*cos(2*t);
y = 2*b*sin(t)-b*sin(2*t);
xp = diff(x, t, 1);
xpp = diff(x, t, 2);
yp = diff(y, t, 1);
ypp = diff(y, t, 2);
n = xp*ypp-yp*xpp;
d = xp^2+yp^2;
n = simplify(n)
d = simplify(d)
n =
4*b^2*(cos(3*t) - 1)
d =
-8*b^2*(cos(3*t) - 1)