-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclass20180118_IT2N2_linear_heart01.m
95 lines (77 loc) · 1.69 KB
/
class20180118_IT2N2_linear_heart01.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
clear;
%common parameter
t=[0.0...
1.5 ...
2.5 ...
5.5];
x=[0.0 ...
1.0 ...
2.0 ...
0.0];
y=[0.0 ...
1.0 ...
0.2 ...
-2.5];
%restrictions for x
Ax=vander(t);%the coordinate value requirements
Ax=Ax(:,end:-1:1);%reverse the order to agree on our formulation
Ax(:,end+1)=[t'].^4;%adding to complete 4th order case
t0=t(3);%at t2...
Ax(end+1,:)=[0 1 2*t0 3*t0^2 4*t0^3];%...extremity required
bx=[x';0];
%restrictions for y
Ay=vander(t);%the coordinate value requirements
Ay=Ay(:,end:-1:1);%reverse the order to agree on our formulation
Ay(:,end+1)=[t'].^4;%adding to complete 4th order case
t0=t(2);%at t1...
Ay(end+1,:)=[0 1 2*t0 3*t0^2 4*t0^3];%...extremity required
by=[y';0];
%solving for parameters
px=Ax\bx;
py=Ay\by;
N=10^3;
tplot=linspace(min(t),max(t),N);
xplot=polyval(px(end:-1:1),tplot);
yplot=polyval(py(end:-1:1),tplot);
%noise
noisex=cumsum(randn(size(xplot)));
xplot=xplot+0.005*noisex;
noisey=cumsum(randn(size(yplot)));
yplot=yplot+0.005*noisey;
Xplot=polyval(px(end:-1:1),t);
Yplot=polyval(py(end:-1:1),t);
%plotting
figure(1);
clf;
vert=3;
horz=3;
subplot(vert,horz,[1:6]);
hold on;
plot(xplot,yplot,'b.-');
plot(-xplot,yplot,'b.-');
plot(Xplot,Yplot,'ro');
grid on;
xlabel('x');
ylabel('y');
%axis([-x(3) x(3) 1.2*y(4) y(2)]);
subplot(vert,horz,[7]);
hold on;
plot(tplot,xplot,'c.-');
plot(t,Xplot,'ro');
grid on;
xlabel('t');
ylabel('x');
subplot(vert,horz,[8]);
hold on;
plot(tplot,yplot,'m.-');
plot(t,Yplot,'ro');
grid on;
xlabel('t');
ylabel('y');
subplot(vert,horz,[9]);
hold on;
plot(tplot,noisex,'c.-');
plot(tplot,noisey,'m.-');
grid on;
xlabel('t');
ylabel('noise');