what is wrong with my code

t=load('t_4l');
vrms=load('vrms_4l');
v0=[45, 47, 70,80, 65];
[v,fi]=lsqnonlin(@(v)fun(v,vrms,t),v0);
function e=fun(v,vrms,t)
e=[vrms- [repmat(v(1),1,6); sqrt((t(2,:)*v(2)^2+t(1,:)*v(1)^2)./(t(2,:)+t(1,:))); ...
sqrt((t(2,:)*v(2)^2+t(3,:)*v(3)^2)./(t(2,:)+t(3,:))); ...
sqrt((t(4,:)*v(4)^2+t(3,:)*v(3)^2)./(t(4,:)+t(3,:))); ...
sqrt((t(4,:)*v(4)^2+t(5,:)*v(5)^2)./(t(4,:)+t(5,:)))]];
t and vrms are all 5*6 matrix
The error is the function, it says that function use is invalid

 Akzeptierte Antwort

David Young
David Young am 16 Jan. 2012

0 Stimmen

The function definition (starting with the word "function") should go into its own m-file, called fun.m in this case. Make sure the m-file is in a folder that is on your MATLAB path, or is the current folder.

1 Kommentar

Titus Edelhofer
Titus Edelhofer am 16 Jan. 2012
Or make the script itself a function, i.e., add e.g.
function vrmsoptim
at the top.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Community Treasure Hunt

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

Start Hunting!

Translated by