Derive function handle with a vector input argument
조회 수: 4 (최근 30일)
이전 댓글 표시
when I run this piece of code
q=[3 2 2 3];
f=@(p,x,y) p(1)*x.^2+p(2).*y.^2+p(3)*x.*y+p(4);
syms 'x'
df=diff(f,x);
dfdx=matlabFunction(df);
A=feval(f,q,2,2);
I get an error says
Index exceeds the number of array elements (1).
What I am trying to do is to cluster my equation coefficients into one vector to make my code compact. In my real application I have 15 coefficients. Any advice if this process is possible?
댓글 수: 0
채택된 답변
Walter Roberson
2024년 1월 11일
이동: Walter Roberson
2024년 1월 11일
q=[3 2 2 3];
f=@(p,x,y) p(1)*x.^2+p(2).*y.^2+p(3)*x.*y+p(4);
syms p [1 4]
syms x y
df=diff(f(p,x,y),x)
dfdx = matlabFunction(df, 'vars', {p, x, y})
A = feval(f,q,2,2)
추가 답변 (2개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Numbers and Precision에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!