need help to code this cubic fit

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

回答(0 个)

类别

帮助中心File Exchange 中查找有关 Polynomials 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by