Evaluate in a single value a function matrix

조회 수: 2 (최근 30일)
JORGE ORDOÑEZ CARRASCO
JORGE ORDOÑEZ CARRASCO 2020년 12월 29일
댓글: JORGE ORDOÑEZ CARRASCO 2020년 12월 29일
Hi i have a to program Newton Raphson in many variables so for example: If i have a function
just like
It is known the Jacobian of f will return in this case a matrix of 2x2. I need to evaluate in a value for example u1=1 and u2=2. But f(1,1) obviously doenst work, i need to evaluate numerically this function and its jacobian and extend this for many variables above 2. By the way the jacobian is:
As you can see for example matrix A(1,1) returns element not a value so how can i evaluate a matrix and a vector in a known number without using x=rand(2,1), x(1),x(2) cause for many variables this will be more dificult to do it.
Thank you

답변 (1개)

Walter Roberson
Walter Roberson 2020년 12월 29일
Use the Symbolic Toolbox to build the equations. Then use matlabFunction with the 'vars' option passing in a cell array that contains a single entry that is the vector of variable names. matlabFunction will then generate an anonymous function with all of the variables extracted from a single vector of inputs.
syms u1 u2
f = [exp(u1)-cos(u2); exp(u2)-u1^2];
fh = matlabFunction(f, 'vars', {[u1, u2]})
fh = function_handle with value:
@(in1)[-cos(in1(:,2))+exp(in1(:,1));exp(in1(:,2))-in1(:,1).^2]
  댓글 수: 4
Walter Roberson
Walter Roberson 2020년 12월 29일
That is not my suggestion. I specifically said that you need to use the vars option with {} and I gave an example to emphasize what hasto be done .
JORGE ORDOÑEZ CARRASCO
JORGE ORDOÑEZ CARRASCO 2020년 12월 29일
Thank you i realized it wasnt your suggestion i just did it again and it work.Thank you so much

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

카테고리

Help CenterFile Exchange에서 Newton-Raphson Method에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by