Converting long program to program with fminsearch

Hello, I have made a long program with random walk with identification criterium. Now i have to delete the random walk and use fminsearch instead of this random walk. My code:
clear all
clc
load pomiary.mat
X=[4 8 3 5 2 8 3 2 6 2]
Y=[6 3 8 3 9 9 9 3 2 7]
x_min=min(X);
x_max=max(X);
os_x=linspace(x_min,x_max,50);
a=rand;
b=rand;
c=rand;
Y_m=a*X.^2+b*X+c;
E=(Y-Y_m);
Q_0=(sum(E)).^2/length(X);
Q_best=Q_0+10;
Qbest=[];
A=[];
B=[];
C=[];
z=1;
j=1;
for i=1:100
while Q_best >= Q_0
if z>10000000
a=A(end);
b=B(end);
c=C(end);
break
end
a=a+randn/50;
b=b+randn/50;
c=c+randn/50;
Y_m=a*(X.^2)+b*X+c;
E=(Y-Y_m).^2;
Q_best=sum(E)/length(X);
z=z+1;
end
if Q_best<Q_0
Q_0=Q_best;
Qbest(j)=Q_best;
A(j)=a;
B(j)=b;
C(j)=c;
Z(j)=j-1;
j=j+1;
end
end
Q_best
figure
os_y=a*(os_x.^2)+b*os_x+c;
plot(X,Y,'+r',os_x,os_y,'r')
I don't know how to start. I think its good choice to delete the part of the program from while loop to end of this loop and use fminsearch here somehow. It's good idea? How to make it?

Answers (0)

Categories

Find more on MATLAB in Help Center and File Exchange

Asked:

on 17 Nov 2017

Community Treasure Hunt

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

Start Hunting!