Matlab符號運算基礎(作業)
【4-1】已知表示式f1 = a + cost與f2 = bsint,試計算f2 - f1 = ?
syms f1 f2 f3 a b t
f1 = a + cos(t)
f2 = b * sin(t)
f3 = f2 - f1 = b * sin(t) - a - cos(t)
【4-2】已知式f1 = a + b與f2 = a + c,試計算f1 X f2 = ?
syms f1 f2 f3 a b c
f1 = a + b
f2 = a + c
f3 = f1 X f2 = f1 * f2 = (a + b) * (a + c)
【4-3】已知f = 2a^2x + a^2y + 8abx + 8b^2x +4aby + 4b^2y,試對其進行因式分解。
syms f f1 a b x y;
f = 2 * a^2 * x + a^2 * y + 8 * a * b * x + 8 * b^2 * x +4 * a * b * y + 4 * b^2 * y
f1 = factor(f) = (a + 2*b)^2*(2*x + y)
【4-4】已知f = x^2 - 2xy - 3y^2 + 3x - 5y + 2,是對其進行因式分解。
syms f f1 x y;
f = x ^ 2 - 2 * x * y - 3 * y ^ 2 + 3 * x - 5 * y + 2
f1 = factor(f) = (x - 3*y + 1)*(x + y + 2)
【4-5】已知f = (x + y) ^ 4,試將其展開。
syms f f1 x y;
f = (x + y) ^ 4
f1 = expand(f) = x^4 + 4*x^3*y + 6*x^2*y^2 + 4*x*y^3 + y^4
【4-6】已知f = lna * e^b - lna * e^b *xy,試對其同類項進行合併。
syms f f1 a b x y;
f = (log(a)) * exp(b) - (log(a)) * exp(b) * x * y
f1 = collect(f) = (-y*exp(b)*log(a))*x + exp(b)*log(a)
【4-7】試對e3 = (cosx)^2 - (sinx)^2 與e4 = x^3 + 3x^2 + 3x + 1進行化簡。
syms e3 e4 f3 f4 x;
f3 = (cos(x)) ^ 2 - (sin(x)) ^ 2
f4 = x ^ 3 + 3 * x ^ 2 + 3 * x + 1
e3 = simplify(f3) = cos(2*x)
e4 = simplify(f4) = (x + 1)^3
【4-8】試求lim((1-cos2x)^(1/2)) / x與lim((1-cos2x)^(1/2)) / x的值。
(x -> -0) (x -> +0)
syms r l x f;
f = sqrt(1-cos(2 * x)) / x;
l = limit(f,x,0,'left') = -2^(1/2)
r = limit(f,x,0,'right') = 2^(1/2)
【4-9】試計算limsin(x) / x、limsin(x) / x與limsin(x) / x的值。
(x->-0) (x->+0) (x->0)
syms l r x f e;
f = sin(x) / x;
l = limit(f,x,0,'left') = 1
r = limit(f,x,0,'right') = 1
e = limit(f,x,0) = 1
【4-10】已知函式f = [1 / (1 + x^2),xe^(x^2);lnsinx,x^x],試求(d^2f) / dx^2。
syms x;
f = [1 / (1 + x ^ 2),x * exp(x ^ 2);log(sin(x)),x ^ x]
d2f = collect(diff(f,x,2)) = [(6*x^2 - 2)/(x^6 + 3*x^4 + 3*x^2 + 1),6*x*exp(x^2) + 4*x^3*exp(x^2); - cos(x)^2/sin(x)^2 - 1,(x*(x^x + 2*x^x*log(x) + x^x*log(x)^2) + x^x)/x]
【4-11】已知函式f = sqrt(x^2 + y^2 + z^2),試求əf / əx、əf / əy與əf / əz。
syms x y z;
f = sqrt(x ^ 2 + y ^ 2 + z ^ 2) = (x^2 + y^2 + z^2)^(1/2)
dfx = diff(f,x,1) = x/(x^2 + y^2 + z^2)^(1/2)
dfy = diff(f,y,1) = y/(x^2 + y^2 + z^2)^(1/2)
dfz = diff(f,z,1) = z/(x^2 + y^2 + z^2)^(1/2)
【4-12】已知函式f = x ^ (y / z),試求əf / əx、əf / əy與əf / əz。
syms x y z;
f = x ^ (y / z)
dfx = diff(f,x,1) = (x ^ (y / z - 1) * y) / z
dfy = diff(f,y,1) = (x ^ (y / z) * log(x)) / z
dfz = diff(f,z,1) = -(x ^ (y / z) * y * log(x)) / z ^ 2
【4-13】已知導函式df / dx = [1 / ((1 + x) ^ (3 / 2)+(1 + x) ^ (1 / 2)),1 / (exp(x) + exp(-x));(exp(x) - 1) / (exp(x) + 1),cos2x / (1 + sinxcosx)],試求f(x)。
syms x;
dfx = [1 / ((1 + x) ^ (3 / 2)+(1 + x) ^ (1 / 2)),1 / (exp(x) + exp(-x));(exp(x) - 1) / (exp(x) + 1),cos(2 * x) / (1 + sin(x)*cos(x))] =
[ 1/((x + 1)^(1/2) + (x + 1)^(3/2)), 1/(exp(-x) + exp(x))]
[ (exp(x) - 1)/(exp(x) + 1), cos(2*x)/(cos(x)*sin(x) + 1)]
f = int(dfx,x) =
[ 2*atan((x + 1)^(1/2)), atan(exp(x))]
[ 2*log(exp(x) + 1) - x, log(cos(x)*sin(x) + 1)]
【4-14】試計算∫[0:Π](xsinx)^2dx與∫[1:2](e^(1/x)) / (x^2)dx的值。
syms x;
f1 = (x * sin(x)) ^ 2 = x ^ 2 * sin(x) ^ 2
f2 = exp(1 / x) / x ^ 2 = exp(1/x)/x^2
intf1 = int(f1,0,pi) = (pi*(2*pi^2 - 3))/12
intf2 = int(f2,1,2) = exp(1) - exp(1/2)
【4-15】試計算I = ∫[0:1]dx∫[(-sqrt(1 - x^2)):(sqrt(1 - x^2))]dy∫[0:1]1dz的值。
syms x y z f1 f2 f3;
f1 = int(1,z,0,1) = 1
f2 = int(f1,y,-sqrt(1 - x^2),sqrt(1 - x^2)) = 2*(1 - x^2)^(1/2)
f3 = int(f2,x,0,1) = pi/2
【4-16】求級數1 + 2 +3 + …… + n與前5項的和。
syms n;
f = n;
sumn = symsum(f,n,1,inf)
sum5 = symsum(f,n,1,5)
【4-17】試求函式f(x) = sin(x) / x的Taylor級數展開式。
syms x;
f = sin(x) / x;
taylorf = taylor(f,x) = x^4/120 - x^2/6 + 1
【4-18】試將函式f(x) = cos(x)展開成(x + π / 3)的冪級數。
syms x;
f = cos(x);
taylorf = collect(taylor(f,-pi / 3)) =
(3^(1/2)*x^5)/240 + ((3^(1/2)*pi)/144 + 1/48)*x^4 + ((3^(1/2)*pi^2)/216 + pi/36 - 3^(1/2)/12)*x^3 + ((3^(1/2)*pi^3)/648 + pi^2/72 - (3^(1/2)*pi)/12 - 1/4)*x^2 + ((3^(1/2)*pi^4)/3888 + pi^3/324 - (3^(1/2)*pi^2)/36 - pi/6 + 3^(1/2)/2)*x + (3^(1/2)*pi)/6 - (3^(1/2)*pi^3)/324 + (3^(1/2)*pi^5)/58320 - pi^2/36 + pi^4/3888 + 1/2
【4-19】對聯立方程組:
{x^2 + xy + x = a
{y^2 + xy + y =b
求當a = 4,b = 28時的x、y。
syms x y x1 y1;
[x1,y1] = solve('x ^ 2 + x * y + x = 4','y ^ 2 + x * y + y = 28','x,y')
x1 =
129^(1/2)/16 - 1/16
- 129^(1/2)/16 - 1/16
y1 =
(7*129^(1/2))/16 - 7/16
- (7*129^(1/2))/16 - 7/16
【4-20】求滿足初始條件的可分離變數微分方程的特解:
xdy + 2ydx = 0,y|(x = 2) = 1
syms x y;
y = dsolve('x * Dy + 2 * y = 0','y(2) = 1','x') = 4/x^2
【4-21】求齊次微分方程的通解:
(x + ycos(y / x))dx - xcos(y / x)dy = 0
syms x y;
y = dsolve('(x + y * cos(y / x)) - x * cos(y / x) * Dy = 0','x') = x*asin(C + log(x))
【4-22】求滿足初始條件的一階線性微分方程的特解:
dy / dx + ycotx = 5e^cos(x),y|(x = π / 2) = -4
syms x y f;
f = 'Dy + y * cot(x) = 5 * exp(cos(x))';
y = dsolve(f,'y(pi / 2) = -4','x') = 1 / sin(x) - (5 * exp(cos(x))) / sin(x)
【4-23】求伯努利微分方程的通解:
dy / dx + y = y^2(cosx - sinx)
syms x y;
y = dsolve('Dy + y - y ^ 2 * (cos(x) - sin(x))','x') =
[0]
[exp(-x)/(C - exp(-x)*sin(x))]
【4-24】求滿足初始條件的二階常係數齊次微分方程的特解:
d^2(y) / dx^2 - 4dy / dx + 3y = 0,y|(x = 0) = 6,dy / dx|(x = 0) = 10
syms x y;
y = dsolve('D2y - 4*Dy + 3*y = 0','y(0) = 6,Dy(0) = 10','x') = 2*exp(3*x) + 4*exp(x)
【4-25】求二街常係數非齊次微分方程的通解:
2d^2(y) / dx^2 + 5dy / dx = 5x^2 -2x -1
syms x y;
y = collect(dsolve('2 * D2y + 5 * Dy - 5 * x ^ 2 + 2 * x +1 = 0','x')) = x^3/3 - (3*x^2)/5 + (7*x)/25 + C33 + C34*exp(-(5*x)/2) - 14/125
【4-26】求尤拉方程的通解:
x^2d^2(y) / dx^2 - 3xdy / dx + 4y = x + x^2ln(x)
syms x y;
y = collect(dsolve('x ^ 2 * D2y - 3 * x * Dy + 4 * y - x - x ^ 2 * log(x) = 0','x')) = ((log(x)^3 + 6*C36*log(x) + 6*C37)*x^2 + 6*x)*6^(-1)
【4-27】化簡複數z = (3 + 4j)(2 - 5j) / 2j,並求real(z),imag(z),conj(z),abs(z)與angle(z)。
z = (3 + 4j) * (2 - 5j) / 2j
Real = real(z) = -3.5000
Imag = imag(z) = -13
Conj = conj(z) = -3.5000 +13.0000i
Abs = abs(z) = 13.4629
Angle = angle(z) = -1.8338
【4-28】已知兩個複數z1 = (3 + 4j)(2 - 5j) / 2j,z2 = j^6 - 4j^21 + j,試求z1 + z2,z1 - z2,z1 * z2,z1 / z2,conj(z1 + z2),abs(z1 - z2),angle(z1z2)。
z1 = (3 + 4j) * (2 - 5j) / 2j = -3.5000 -13.0000i
z2 = j ^ 6 - 4 * j ^ 21 + j = -1.0000 - 3.0000i
z1 + z2 = -4.500 - 16.000i
z1 - z2 = -2.5000 - 10.000i
z1 * z2 = -35.500 + 23.500i
z1 / z2 = 4.250 + 0.250i
conj(z1 + z2) = -4.5000 +16.0000i
abs(z1 - z2) = 10.3078
angle(z1 * z2) = 2.5568
【4-29】試計算1^sqrt(2)與j^j。
1 ^ sqrt(2) = 1
j ^ j = 0.2079
【4-30】試計算ln(-3 + 4j) 與lnj。
log(-3 + 4j) = 1.6094 + 2.2143i
log(j) = 0 + 1.5708i