Assignment 10

advertisement
ASSIGNMENT 10
Task1A)
load Terrain.m %load file
a=Terrain(:,1); %define variables
b=Terrain(:,2);
plot(a,b,'ro') %plot original data
Task1B)
a_fit=linspace(0,200,10000000); %give a new variable values
c=polyfit(a,b,8); %fit the original data to the 8th degree
{_Warning: Polynomial is badly conditioned. Add points with distinct X
values, reduce the degree of the polynomial, or try centering
and scaling as described in HELP POLYFIT.}_
> In <a href="matlab: opentoline('C:\Program
Files\MATLAB\R2010b\toolbox\matlab\polyfun\polyfit.m',80,1)">polyfit at
80</a>
b_fit=polyval(c,a_fit); %create new variable from a_fit and the polyfit
plot(a_fit,b_fit); %plot the polyfit line
135
130
125
120
115
110
105
100
95
90
85
0
20
40
60
80
100
120
140
160
180
200
function y=terrainfun(x);
y=(2911447260440125*conj(x).^8)/158456325028528675187087900672 (5157665782976401*conj(x).^7)/309485009821345068724781056 +
(3717746025618033*conj(x).^6)/604462909807314587353088 (2774011576597617*conj(x).^5)/2361183241434822606848 +
(279829002710565*conj(x).^4)/2305843009213693952 (910229435104981*conj(x).^3)/144115188075855872 +
(8661815132271239*conj(x).^2)/72057594037927936 +
(1481575189149261*conj(x))/2251799813685248 +
3515827222982639/35184372088832;
area=quad('terrainfun',0,200)
area =
2.1478e+004
Task2A/2B)
xlsread ('AccidentTrace.xlsx'); %load file
a=ans(:,1); %assign variable time
b=ans(:,2); %assign variable for acceleration)
a_fit=linspace(0,20,10000000); %assign new variable for fit line
plot(a,b,'go') %plot
hold
Current plot held
c=polyfit(a,b,9); %create a fit line to 9th degree
{_Warning: Polynomial is badly conditioned. Add points with distinct X
values, reduce the degree of the polynomial, or try centering
and scaling as described in HELP POLYFIT.}_
> In <a href="matlab: opentoline('C:\Program
Files\MATLAB\R2010b\toolbox\matlab\polyfun\polyfit.m',80,1)">polyfit at
80</a>
b_fit=polyval(c,a_fit) %create another variable in relation to fit line and
a_fit;
plot(a_fit,b_fit)
1
0
-1
-2
-3
-4
-5
-6
-7
0
2
4
6
8
10
12
14
16
18
20
Task 3A)
syms x %define x
y=exp(sin(x)^2); %input function
subs(diff(y,x,5),x,[1:.1:2])%derive the function to the 5th degree then
substitute x values with new x values [1:.1:2]
ans =
Columns 1 through 2
68.4060
132.3649
Columns 3 through 4
180.8892
192.7663
Columns 5 through 6
155.4732
73.4422
Columns 7 through 8
-30.9770 -125.8634
Columns 9 through 10
-183.4140 -191.3088
Column 11
-155.7122
Task 3B)
function y=A10_Task3B(x)
y=(tan(x)./(1+x.^3));%create function for quad evaluation
Q=quad('A10_Task3B',-5,5)
{_Warning: Infinite or Not-a-Number function value encountered.}_
> In <a href="matlab: opentoline('C:\Program
Files\MATLAB\R2010b\toolbox\matlab\funfun\quad.m',113,1)">quad at 113</a>
Q =
-Inf
Q=quad('A10_Task3B',0,5)
{_Warning: Minimum step size reached; singularity possible.}_
> In <a href="matlab: opentoline('C:\Program
Files\MATLAB\R2010b\toolbox\matlab\funfun\quad.m',107,1)">quad at 107</a>
Q =
2.1314
Task4A)
y=dsolve('Dy=3*y-4*t+7','y(0)=5')%use math toolbox
y =
(4*t)/3 + (62*exp(3*t))/9 - 17/9
fplot(@(t)((4*t)/3 + (62*exp(3*t))/9 - 17/9),[0,3])%plot t
4
6
x 10
5
4
3
2
1
0
0
0.5
1
1.5
2
2.5
3
Task4B)
y=dsolve('D2y=10+5*y','y(0)=0','Dy(0)=1');
simplify(y)
ans =
4*sinh((5^(1/2)*t)/2)^2 + (5^(1/2)*sinh(5^(1/2)*t))/5
fplot(@(t) (4*sinh((5^(1/2)*t)/2)^2 + (5^(1/2)*sinh(5^(1/2)*t))/5),[0 5])
4
9
x 10
8
7
6
5
4
3
2
1
0
0
0.5
1
1.5
2
2.5
3
3.5
4
4.5
5
Task5A)
function y=A10_Task52(t,z);
y=[z(2);f.*cos(w.*t)]%original function needed and f and w can be changed
manually
function y=A10_Task52(t,z); %bullet 2
y=[z(2);0.*cos(0.*t)-z(1)];
[t,z]=ode45('A10_Task52',[0,10],[0,1]);
plot(t,z)%period seems to be 6
1
0.8
0.6
0.4
0.2
0
-0.2
-0.4
-0.6
-0.8
-1
0
1
2
3
4
5
6
7
8
9
10
function y=A10_Task52(t,z);
y=[z(2);1.*cos(0.9.*t)-z(1)];%bullet 3
[t,z]=ode45('A10_Task52',[0,70],[0,0]);
plot(t,z)
15
10
5
0
-5
-10
-15
0
10
20
30
40
function y=A10_Task52(t,z);
y=[z(2);1.*cos(1.*t)-z(1)];%bullet 4
[t,z]=ode45('A10_Task52',[0,40],[0,0]);
plot(t,z)
50
60
70
20
15
10
5
0
-5
-10
-15
-20
0
5
10
15
20
25
30
35
Task5B)
function y=A10_Task51(t,z); %create ODE function
y=[z(2);2.*(1-z(1).^2).*z(2)+z(1)];%ODE Function
40
tspan=[0 10];
z0=[2;0];
[t,z]=ode45('A10_Task51',tspan,z0);
plot(t,z)
4
3.5
3
2.5
2
1.5
1
0.5
0
0
1
2
Task6)
a=[1 2 3;3 3 4;2 3 3];
b=[1;1;2];
3
4
5
6
7
8
9
10
c=a\b
c =
-0.5000
1.5000
-0.5000
c=[a b]
c =
1
3
2
2
3
3
3
4
3
1
1
2
d=rref(c)
d =
1.0000
0
0
0
1.0000
0
0
0
1.0000
-0.5000
1.5000
-0.5000
Download