Problem 5.4

advertisement
Problem 5.4
(a) This problem is solved by the provided Matlab script file run lsquare.m. The resulting
diagram is shown below (left diagram). The output in the Matlab command window is
b =
85.9804
m =
1.0830e+003
E =
1.3100e+005
(b) For finding k, n in r = kwn we transform the data to logarithmic data. The last three lines
in the script file run lsquare.m are modified to
x=log(w);y=log(r);
[b,n,E]=lsquare(x,y);
b,k=exp(b),n,E
which produces the following output:
b =
7.0182
k =
1.1167e+003
n =
-0.2409
E =
0.7807
The result of this computation suggests a (−1/4)–power law instead of a (−1/3)–power law.
The resulting log–log plot of w versus r is show below (middle diagram).
1
Problem 5.5
To match data (yi , xi ) to a quadratic function y = c0 + c1 x + c2 x2 , the function file lsquare.m is
modified to
function [c0,c1,c2,E]=lsquad(x,y)
%Computation of b,m
P=length(x);
X=[ones(P,1) x x.^2];
vec=X\y;
c0=vec(1);
c1=vec(2);
c2=vec(3);
%Computation of error
dy=y-c0-c1*x-c2*x.^2;
E=dy’*dy;
%Plot results
plot(x,y,’ko’,x,c0+c1*x+c2*x.^2,’k-v’)
legend(’data’,’model’)
and saved as lsquad.m. The last line in the script file run lsquare.m is then modified to
[c0,c1,c2,E]=lsquad(x,y)
which produces the following output:
c0 =
22.5156
c1 =
2.1804e+003
c2 =
-1.7580e+003
E =
5.4214e+004
The graph of the quadratic fit is shown in the right diagram below.
Diagrams:
800
700
800
7
data
model
data
model
6.5
700
600
5.5
500
5
400
r
400
r
6
500
ln(r)
600
300
4.5
300
200
4
200
100
3.5
100
0
0
0.1
0.2
0.3
w−1/3
0.4
0.5
0.6
0.7
3
0
data
model
5
10
ln(w)
2
15
0
0
0.1
0.2
0.3
0.4
w−1/3
0.5
0.6
0.7
Download