实验五 MATLAB符号计算.docx
《实验五 MATLAB符号计算.docx》由会员分享,可在线阅读,更多相关《实验五 MATLAB符号计算.docx(10页珍藏版)》请在冰豆网上搜索。
实验五MATLAB符号计算
实验五MATLAB符号计算
一、实验目的
1.掌握定义符号对象的方法
2.掌握符号表达式的运算法则
3.掌握求符号极限、导数和积分的方法
4.掌握代数方程符号求解的方法
5.掌握常微分方程符号求解的方法
二、实验内容
1.分解因式
(1)
(2)5135
A=sym('x^4-y^4');
factor(A)
ans=
(x-y)*(x+y)*(x^2+y^2)
A=sym('5123');
factor(A)
ans=
(47)*(109)
2.
symsx;
f=(x*(exp(sin(x))+1)-2*(exp(tan(x))-1))/(sin(x)^3);
limit(f,x,0)
ans=
-1/2
3.已知
,分别求
、
、
symsatx;
A=sym('[a^x,t^3;t*cos(x),log(x)]');
a=diff(A,x)
b=diff(A,t,2)
c=diff(a,t)
a=
[a^x*log(a),0]
[-t*sin(x),1/x]
b=
[0,6*t]
[0,0]
c=
[0,0]
[-sin(x),0]
4.求符号定积分
x=sym('x');
f=exp(x)*((1+exp(x))^2);
I=int(f,0,log
(2));
I
I=
-7/3+exp(6243314768165359/9007199254740992)+exp(6243314768165359/9007199254740992)^2+1/3*exp(6243314768165359/9007199254740992)^3
5.求方程
的符号解
f=sym('x^2+9*sqrt(x+1)-1=0');
x=solve(f)
x=
[-1+(-1/6*(972+12*6465^(1/2))^(1/3)-4/(972+12*6465^(1/2))^(1/3))^2]
[-1+(1/12*(972+12*6465^(1/2))^(1/3)+2/(972+12*6465^(1/2))^(1/3)+1/2*i*3^(1/2)*(-1/6*(972+12*6465^(1/2))^(1/3)+4/(972+12*6465^(1/2))^(1/3)))^2]
[-1+(1/12*(972+12*6465^(1/2))^(1/3)+2/(972+12*6465^(1/2))^(1/3)-1/2*i*3^(1/2)*(-1/6*(972+12*6465^(1/2))^(1/3)+4/(972+12*6465^(1/2))^(1/3)))^2]
[-1+(-1/6*(972+12*6465^(1/2))^(1/3)-4/(972+12*6465^(1/2))^(1/3))^2]
[-1+(1/12*(972+12*6465^(1/2))^(1/3)+2/(972+12*6465^(1/2))^(1/3)+1/2*i*3^(1/2)*(-1/6*(972+12*6465^(1/2))^(1/3)+4/(972+12*6465^(1/2))^(1/3)))^2]
[-1+(1/12*(972+12*6465^(1/2))^(1/3)+2/(972+12*6465^(1/2))^(1/3)-1/2*i*3^(1/2)*(-1/6*(972+12*6465^(1/2))^(1/3)+4/(972+12*6465^(1/2))^(1/3)))^2]
[-1]
6.求微分方程的符号解,并与数值解进行比较
数值解
y=dsolve('D2y+4*Dy+29','y(0)=0,Dy(0)=0','x')
y=
-29/4*x+29/16-29/16*exp(-4*x)
解析解:
先建立M文件
functiony=sys(x,y)
y=[-4*y
(1)-29*y
(2);y
(1)];
再求解微分方程
x0=0;xf=20;
[x,y]=ode45('sys',[x0,xf],[0,0]);
[x,y];
plot(x,y(:
2))
ans=
000
0.0000-0.0001-0.0000
0.0000-0.0001-0.0000
0.0000-0.0002-0.0000
0.0000-0.0002-0.0000
0.0000-0.0005-0.0000
0.0000-0.0007-0.0000
0.0000-0.0010-0.0000
0.0000-0.0012-0.0000
0.0001-0.0025-0.0000
0.0001-0.0037-0.0000
0.0002-0.0050-0.0000
0.0002-0.0062-0.0000
0.0004-0.0125-0.0000
0.0006-0.0188-0.0000
0.0009-0.0250-0.0000
0.0011-0.0313-0.0000
0.0022-0.0625-0.0001
0.0032-0.0935-0.0002
0.0043-0.1245-0.0003
0.0054-0.1553-0.0004
0.0108-0.3072-0.0017
0.0162-0.4560-0.0037
0.0217-0.6015-0.0066
0.0271-0.7439-0.0102
0.0456-1.2076-0.0283
0.0640-1.6383-0.0547
0.0825-2.0382-0.0887
0.1010-2.4097-0.1299
0.1318-2.9699-0.2127
0.1625-3.4652-0.3118
0.1932-3.9031-0.4252
0.2240-4.2904-0.5513
0.2669-4.7575-0.7457
0.3098-5.1508-0.9585
0.3527-5.4817-1.1869
0.3956-5.7604-1.4283
0.4521-6.0621-1.7622
0.5086-6.3027-2.1115
0.5650-6.4937-2.4731
0.6215-6.6461-2.8443
0.6872-6.7863-3.2859
0.7530-6.8939-3.7355
0.8187-6.9758-4.1916
0.8844-7.0387-4.6525
0.9633-7.0964-5.2096
1.0421-7.1383-5.7707
1.1209-7.1681-6.3347
1.1998-7.1897-6.9009
1.2961-7.2095-7.5940
1.3923-7.2228-8.2888
1.4886-7.2311-8.9848
1.5849-7.2367-9.6815
1.7066-7.2422-10.5620
1.8282-7.2456-11.4432
1.9499-7.2469-12.3248
2.0715-7.2477-13.2066
2.2319-7.2492-14.3690
2.3923-7.2499-15.5317
2.5527-7.2496-16.6945
2.7131-7.2494-17.8574
2.9323-7.2505-19.4469
3.1516-7.2508-21.0365
3.3709-7.2498-22.6264
3.5902-7.2491-24.2163
3.8621-7.2537-26.1866
4.1340-7.2549-28.1578
4.4059-7.2484-30.1309
4.6779-7.2450-32.1032
4.8535-7.2490-33.3755
5.0291-7.2508-34.6483
5.2047-7.2492-35.9220
5.3804-7.2480-37.1956
5.5560-7.2496-38.4684
5.7316-7.2503-39.7415
5.9072-7.2497-41.0150
6.0829-7.2492-42.2884
6.3059-7.2507-43.9053
6.5290-7.2512-45.5226
6.7521-7.2497-47.1403
6.9752-7.2487-48.7579
7.2329-7.2536-50.6254
7.4907-7.2550-52.4938
7.7485-7.2485-54.3641
8.0062-7.2449-56.2338
8.1832-7.2491-57.5158
8.3602-7.2509-58.7984
8.5371-7.2492-60.0819
8.7141-7.2479-61.3653
8.8911-7.2496-62.6480
9.0681-7.2504-63.9308
9.2450-7.2497-65.2141
9.4220-7.2491-66.4973
9.6423-7.2507-68.0940
9.8626-7.2512-69.6910
10.0829-7.2497-71.2885
10.3032-7.2487-72.8859
10.5566-7.2533-74.7221
10.8100-7.2546-76.5591
11.0635-7.2487-78.3980
11.3169-7.2453-80.2361
11.4971-7.2493-81.5417
11.6773-7.2511-82.8479
11.8576-7.2493-84.1550
12.0378-7.2479-85.4619
12.2180-7.2497-86.7681
12.3982-7.2505-88.0745
12.5784-7.2497-89.3813
12.7587-7.2490-90.6881
12.9782-7.2507-92.2790
13.1977-7.2513-93.8703
13.4172-7.2496-95.4621
13.6367-7.2486-97.0537
13.8853-7.2530-98.8552
14.1339-7.2544-100.6575
14.3826-7.2488-102.4615
14.6312-7.2455-104.2649
14.8569-7.2544-105.8987
15.0825-7.2574-107.5340
15.3082-7.2480-109.1723
15.5338-7.2423-110.8097
15.7161-7.2491-112.1293
15.8983-7.2521-113.4499
16.0806-7.2488-114.7720
16.2628-7.2463-116.0939
16.4323-7.2490-117.3216
16.6017-7.2503-118.5497
16.7711-7.2494-119.7783
16.9406-7.2488-121.0069
17.1387-7.2502-122.4433
17.3369-7.2508-123.8800
17.5351-7.2497-125.3170
17.7333-7.2490-126.7540
17.9739-7.2516-128.4978
18.2145-7.2524-130.2421
18.4551-7.2493-131.9873
18.6957-7.2475-133.7323
18.9403-7.2548-135.5035
19.1849-7.2570-137.2759
19.4294-7.2480-139.0512
19.6740-7.2428-140.8255
19.7555-7.2449-141.4159
19.8370-7.2463-142.0065
19.9185-7.2473-142.5972
20.0000-7.2480-143.1880
x1=0:
0.01:
20;
plot(x,y(:
2),'r-',x1,y1,'b-')
三、实验收获与体会
在实际运用中除了存在大量的数值计算外,还有对符号对象进行运算的,而且有时候用符号对象进行运算是更简单明了的,就像求解常微分方程用符号求解就比数值运算更方便。
实验五让我掌握了MATLAB中用符号对象的方法和相关运算法则和解决方程、微积分的方法。