|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
# u& }1 ?$ a \解题思路:
3 R6 z: A# f: ]0 {( w. `1 p 这种是求解当方程数量多于未知数时,可以使用正规方程来求解。 J6 M' t- `! p2 A& W! ?
这种linearization方法是将pt = c1*e^(c2*t),两边取ln得到线性方程组。
( l. R+ W( H7 m$ R 线性化之后呢就要进行方程求解,也就是A'Ax = A'b,那么使用x = ((A')*A)\((A')*b);就可以求出x的值,也就是lnc1和c2的值。记得一定要像上面那样写,A'*A在前面,A'*b在后面。
8 K. ?& c H8 |! y. `. Q$ i! Y# n) h2 M
代码如下:* F9 L6 @! f5 J+ Y
% page 210 computer problem 3
+ e5 w Z+ R1 r; n7 l% using linearization to evslute the populstion of 19801 Q3 O7 f, n6 x1 R" _; @7 W1 J
% Input: None* F K$ F$ o. N; u$ g
% Output:None
' r) c9 m( V" P, E I0 h7 I% Display the the result and the error of the caculation
; G/ I6 o& D& s' i" gfunction page_210_3% _6 n2 [ n M( N; Q
format long
( |' e. P" w- \8 y: F; x8 z% \A = [1 0;1 10;1 30;1 40]; %这里的0是以1960年为起点的,所以1970年为104 |: U4 m' u7 \
b = [log(3039585530);log(3707475887);log(5281653820);log(6079603571)];+ S1 W# w7 \" k
x = ((A')*A)\((A')*b);# Z7 k1 o- _# [0 `: p
c1 = vpa(exp(x(1)),10)
, q2 {2 \# N: Y3 S" {( z2 `7 `c2 = vpa(x(2),6)- n2 a# d% E- ]/ }: J3 c
syms t;
8 X* B/ s. B0 h! m. R; zdisp('使用linearation的方法得到人口的表达式为:');+ M4 l1 w- H9 Z& ?" o
Pt = vpa(c1*exp(c2*(t-1960)),10)/ k) n/ ~' g( A, ]# ]( v( ~
disp('使用linearation的方法估计1980年人口的为:');: s3 y/ O: q- m0 E! n; N6 L, w" N- D6 o
Pro_1980 = vpa(subs(Pt,1980),10)( X: R- q2 T5 m, V
disp('使用linearation的方法估计1980年人口与实际人口误差为:');) H8 g, s3 Q" w. W+ ?2 y
vpa(abs(Pro_1980 - 4452584592),9) |
|