need help to code this cubic fit

2 views (last 30 days)
Haris Hameed
Haris Hameed on 18 Aug 2020
Edited: Haris Hameed on 18 Aug 2020
hello
i need some guidace to code the cubic fit optimization in matlab
i coded it initially like this
clc
clear all
syms X;
f=X.^4+2.*X+4;
d_dx = diff(f, X);
dd_dx = diff(d_dx, X);
i=2;
iter=10;
%xk=0;
xk(1)=0.1;
xk(2)=0.2;
u1=subs(d_dx,X,xk(1))+subs(d_dx,X,xk(2))-3*((subs(f,X,xk(1))-subs(f,X,xk(2)))/xk(1)-xk(2));
u2=sqrt(u1^2-subs(d_dx,X,xk(1))*subs(d_dx,X,xk(2)));
xk(3)=xk(2)-(xk(2)-xk(1))*((subs(d_dx,X,xk(2))+u2-u1)/((subs(d_dx,X,xk(2)))-(subs(d_dx,X,xk(1)))+2*u2));
while i<iter
i=i+1;
u1=subs(d_dx,X,xk(i-1))+subs(d_dx,X,xk(i))-3*((subs(f,X,xk(i-1))-subs(f,X,xk(i)))/xk(i-1)-xk(i));
u2=sqrt(u1^2-subs(d_dx,X,xk(i-1))*subs(d_dx,X,xk(i)));
xk(i+1)=xk(i)-(xk(i)-xk(i-1))*((subs(d_dx,X,xk(i))+u2-u1)/((subs(d_dx,X,xk(i)))-(subs(d_dx,X,xk(i-1)))+2*u2));
%
%
end
xk

Answers (0)

Categories

Find more on Interpolation in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!