Here is the MATLAB solution below for the question above. I need to change the c
ID: 3755923 • Letter: H
Question
Here is the MATLAB solution below for the question above. I need to change the code below to something else, but I need the solutions to match each other. (Also try not to copy answer posted on chegg already)
clc; clear all; close all; % reset matlab w
t = linspace(-0.75, 0.25, 7)';
b = [0;-.1;.5;1;.8;.5;0;0];
A1 = fliplr(vander(t(1:4)));
B1 = A1(1:3,:);
A2 = fliplr(vander(t(4:7)));
B2 = A2(2:4,:);
C1 = [0 1 2*t(4) 3*t(4)^2];
A = [B1 zeros(3,4);zeros(3,4) B2;A1(4,:) -A1(4,:);C1 -C1];
x = A
t_p = linspace(t(1),t(4), 50)';
t_q = linspace(t(4),t(7), 50)';
p = polyval(flip(x(1:4)),t_p);
q = polyval(flip(x(5:8)),t_q);
figure;
plot(t([1:3,5:7]),b(1:6),'*')
hold on;
plot(t_p,p,'r-',t_p(50),p(50),'s');
hold on;
plot(t_q,q,'g-',t_q(1),q(1),'d');
grid on;
legend 'Data' 'Poly p' 'Poly p at t_4' 'Poly q' 'Poly q at t_4'
xlabel 't'; ylabel 'y'
Explanation / Answer
CODE;
clc; clear all; close all; % reset matlab w
t = linspace(-0.75, 0.25, 7)';
b = [0;-.1;.5;1;.8;.5;0;0];
A1 = fliplr(vander(t(1:4)));
B1 = A1(1:3,:);
A2 = fliplr(vander(t(4:7)));
B2 = A2(2:4,:);
C1 = [0 1 2*t(4) 3*t(4)^2];
A = [B1 zeros(3,4);zeros(3,4) B2;A1(4,:) -A1(4,:);C1 -C1];
x = A
t_p = linspace(t(1),t(4), 50)';
t_q = linspace(t(4),t(7), 50)';
p = polyval(flip(x(1:4)),t_p);
q = polyval(flip(x(5:8)),t_q);
figure;
plot(t([1:3,5:7]),b(1:6),'*')
hold on;
plot(t_p,p,'r-',t_p(50),p(50),'s');
hold on;
plot(t_q,q,'g-',t_q(1),q(1),'d');
grid on;
legend 'Data' 'Poly p' 'Poly p at t_4' 'Poly q' 'Poly q at t_4'
xlabel 't'; ylabel 'y'