[go: up one dir, main page]

0% found this document useful (0 votes)
16 views1 page

Function: %crea Una Matriz

Download as rtf, pdf, or txt
Download as rtf, pdf, or txt
Download as rtf, pdf, or txt
You are on page 1/ 1

function [ p] = TrazadorCubicoJeanCarlos(x,y)

h=[x(2)-x(1)];
N=length(x);
Dim=N-2
do=4.*ones(Dim,1);
dm=[ones(Dim-1,1);0];
dM=[0;ones(Dim-1,1)];
B=[dm do dM];
b=[-1 0 1];
A=spdiags(B,b,Dim,Dim); %crea una matriz
S=inv(A)*(6.*diff(y,2))./(h.^2);
S=[0;S;0];
%construyo la matriz
p=zeros(N-1,4);
for n=1:N-1
p(n,1)=[y(n)];
p(n,2)=[(y(n+1)-y(n))./h-h.*(S(n+1)+2.*S(n))./6];
p(n,3)=[S(n)./2];
p(n,4)=[(S(n+1)-S(n))./(6.*h)];
end
figure();
plot(x,y,'r'),hold on,grid on;
for n=1:N-1
q=@(u) p(n,1)+p(n,2).*(u-x(n))+p(n,3).*(u-x(n)).^2+p(n,4).*(u-x(n)).^3;
u=[x(n):0.01:x(n+1)];
q1=q(u);
plot(u,q1,'b','LineWidth',3);
pause(2);
end
end

You might also like