Plugging in values into matlab function

조회 수: 13 (최근 30일)
Jb179
Jb179 2017년 12월 2일
편집: Walter Roberson 2017년 12월 2일
Hello, I want to know how to plug in multiple values into an equation that contains multiple variables. I've read using the anonymous function might be useful but I'm not entirely sure. Below is an example of what I mean
P = [eq1;eq2]
x = 1 , y = 3, z = 5
I want matlab to be able to plug in the values of x, y and z into the P matrix (for eq1 and eq2) so that it produces a matrix with number values, so something like P = [2;2]
  댓글 수: 4
Walter Roberson
Walter Roberson 2017년 12월 2일
So is that
P = {'x^2 +2y +3z'; 'x*y -2z^2'}
or is that
P = ['x^2 +2y +3z'; 'x*y -2z^2 ']
or is it
syms x y z
P = [x^2 +2*y +3*z; x*y -2*z^2]
or is it
syms x y z
P = [x^2 + 2*y + 3*z; x*y - 2*z^2]
or something else?
Jb179
Jb179 2017년 12월 2일
I basically want to do something similar to this:
f= @(x) ... [ 2*x(1)^2+x(1)*x(2)-x(1)-2 ;x(1)^2-x(2) ];
J= @(x) ... [ 4*x(1)+x(2)-1 x(1) ;2*x(1) -1 ];
x=[0.9; 1.1];
however instead of using x(1) I would you x or x(2) would be z

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

답변 (1개)

Walter Roberson
Walter Roberson 2017년 12월 2일
편집: Walter Roberson 2017년 12월 2일
Have you considered possibilities such as
x = @(V) V(1);
y = @(V) V(2);
z = @(V) V(3);
f = @(V) [ 2*x(V)^2+x(V)*y(V)-X(V)-2; x(V)^2-y(V) ];
J = @(V) [ 4*x(V)+y(V))-1*x(V); 2*x(V)-1 ];
?

카테고리

Help CenterFile Exchange에서 Mathematics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by