You are on page 1of 2

function Ma=cubicTracerFn(x, y)

n = length(x)
M = zeros(n,n)
Ma = zeros(n,n-1)
M(1,1)=1
M(n,n) = 1
h = zeros(1,n-1)
c = zeros(n,1)
C = zeros(n,1)
c(1,1) =0
c(n,1) = 0
for i = 1: length(h)
h(1,i)= [x(i+1)-x(i)]
end
//lleno matriz
for j=2:n-1
M(j,j-1) = h(j-1)
M(j,j) = 2*(h(j-1)+h(j))
M(j,j+1) = h(j)
c(j,1) = [(3*(y(j+1)-y(j)))/h(j)] - [(3*(y(j)-y(j-1)))/h(j-1)]
end
C = inv(M)*c

for J=1: n-1


Ma(J,1)=[C(J+1,1)-C(J,1)]/(3*h(J))
Ma(J,2)= C(J,1)
Ma(J,3)=[(y(J+1)-y(J))/h(J)]-[(C(J+1)+(2*C(J)))*h(J)/3]
Ma(J,4)= y(J)

end
disp(Ma)

endfunction

function P=polyn(Ma,x)
[f,c]= size(Ma)
P=zeros(f-1,1)
s=poly([0 1],"x","c")
temp=poly([0 1],"x","c")
for k=1:f-1
s=Ma(k,1)*[(temp-x(1))*(temp-x(1))*(temp-x(1))]+ Ma(k,2)*[(temp-x(1))*(temp-x(1))]
+ Ma(k,3)*[(temp-x(1))]+ Ma(k,4)
P(k,1)=s
end
disp(P)
endfunction

/*

Rta 26a:
los valores del vector en X estan en horas con el fin de tener millas/horas
x=[0 0.25 0.5 1 1.25]
y=[0 0.00621 0.00746 0.02655 0.0336]
x=[0 0.25 0.5 0.75]

evaluar en el ultimo poli


3
S1[ 0.0318393x -0.1119895x ]

2 3
S2=[ 0.00621 +0.0108413x -0.0839921x +0.2425075x ]

2 3
S3=[ 0.00746 +0.0143154x +0.0978885x -0.1003187x ]

2 3
S4=[ 0.02655 +0.0369649x -0.0525895x +0.0701193x ]

b
evaluar el polinomio 3

*/

You might also like