using matlabfunction to declare variables
조회 수: 5 (최근 30일)
이전 댓글 표시
I have three equations with names 'equn1, equn2, equn3'. Variables in those equations are declared as :
lam = sym('lam', [1 3] ).
To solve those equations, i am writing the code like this :
solu_fsolve = []; value = []; lam(1) = 0; lam(2) = 0; lam(3) = 0;
fh = matlabFunction([equn1;equn2;equn3],'vars',{[ lam(1), lam(2), lam(3)]});
options = optimset('Display','off','TolFun',eps);
[solu_fsolve,value] = fsolve(fh, [ 1,1,1] ,options ) ;
But, when i execute this code , i am getting an error like :
??? Error using ==> sym.matlabFunction>checkVars at 155
Variable names must be valid MATLAB variable names.
Error in ==> sym.matlabFunction at 104
vars = checkVars(funvars,opts);
Can anyone please tell me how to declare the array as variables in matlabfunction?
Please help.
--kalpana
댓글 수: 0
채택된 답변
Alan Weiss
2014년 11월 3일
When you execute the first line of code you make lam a symbolic vector:
lam = sym('lam', [1 3] )
lam =
[ lam1, lam2, lam3]
However, you later change those variables to symbolic zeros instead of leaving them as variables.
lam(1) = 0; lam(2) = 0; lam(3) = 0;
Remove that line of code and I expect that matlabFunction will work just fine.
Alan Weiss
MATLAB mathematical toolbox documentation
댓글 수: 0
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!