Info

此问题已关闭。 请重新打开它进行编辑或回答。

MAKE OBJECTIVE FUNCTION FROM ALGORITHM

1 次查看(过去 30 天)
jason law
jason law 2020-5-11
关闭: MATLAB Answer Bot 2021-8-20
Hi, Can I know how to make this algorithm to become function in matlab because I want to use fmincon in matlab to find minimum J
f=[];
abs_H=[];
t=[rand(101,2)];
for x=1:101; % number of frequency
for y=1:n; %number of t
Fr(x,y)=cos(2*pi*f(x)*t(y)); %real number of F
Fi(x,y)=-i*sin(2*pi*f(x)*t(y)); % imaginary number of F
end
end
Fr_T=Fr';
Fi_T=Fi';
A=(Fr_T*Fr)+(Fi_T*Fi);
B=(Fr_T*fr)+(Fi_T*fi);
a=lsqminnorm(A,B) ; % solve tp get a set of a
J(z)=sum((a-abs_H))^2; % to find the minimum of J from measured data
end
J_min=min(J);

回答(1 个)

Cris LaPierre
Cris LaPierre 2020-8-2
You can use the Refactor tool in live scripts to convert selected code to a function. See this page.

Community Treasure Hunt

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

Start Hunting!

Translated by