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

 채택된 답변

David Young
David Young 2012년 1월 16일

0 개 추천

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

Titus Edelhofer
Titus Edelhofer 2012년 1월 16일
Or make the script itself a function, i.e., add e.g.
function vrmsoptim
at the top.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 File Operations에 대해 자세히 알아보기

질문:

2012년 1월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by