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

 Respuesta aceptada

David Young
David Young el 16 de En. de 2012

0 votos

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 comentario

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

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre File Operations en Centro de ayuda y File Exchange.

Preguntada:

el 16 de En. de 2012

Community Treasure Hunt

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

Start Hunting!

Translated by