Plugging in values into matlab function
显示 更早的评论
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
2017-12-2
What is the data type of eq1 and eq2 ?
Jb179
2017-12-2
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
2017-12-2
回答(1 个)
Walter Roberson
2017-12-2
编辑:Walter Roberson
2017-12-2
See https://www.mathworks.com/matlabcentral/answers/369859-i-have-an-array-of-anonymous-functions-2x2-array-4-functions-each-with-2-variables-x1-and-x2-an#answer_293659 which is a bit different but gives an idea of how messy it can start to get.
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 ];
?
类别
在 帮助中心 和 File Exchange 中查找有关 Mathematics 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!