Matlab function input define

1 次查看(过去 30 天)
Moli Wang
Moli Wang 2017-3-29
I want to define a matlab function that can generate the deformation gradients etc...so I wrote something like this
function [F,R,U]=deformationgradients[X,Y,Z]
However, I want X,Y,Z of the inputs could be any functions like X=ax^2 or X=xyz or X=z+6; Y=ax+by or Y=6z+3x; Z=x^2 or Z=y+z; where capital X,Y,Z are the total displacements in x,y,z direction.
How can I do that?

回答(1 个)

Richard Zappulla
Richard Zappulla 2017-3-30
In my opinion, I would look at passing function handles into your function for X, Y, or Z. The workflow would look something like this:
X = @(x,y,z)(x.*y.*z);
Y = @(x,z)(6.*z + 3.*x);
Z = @(y,z)(y+z);
[F,R,U] = deformationgradients(X,Y,Z,x,y,z);
If you plan on handling vector data, note the ".*" (element-wise multiplication) inside each function. If you are planning on performing matrix-multiplication, remove the ".". Then inside your function, it could look something like:
function [F,R,U] = deformationgradients(X,Y,Z,x,y,z)
someVar1 = X(x,y,z);
someVar2 = X(x,y,z) + Y(x,z);
.
.
.
end
where X,|Y|,and Z are the function handles and x,|y|, and z are data.
Hope this is what you are looking for.
  1 个评论
Stephen23
Stephen23 2017-3-30
编辑:Stephen23 2017-3-30
It would probably be simpler to define each function to accept all of x, y, and z, even if they are not used:
X = @(x,y,z)(x.*y.*z);
Y = @(x,y,z)(6.*z + 3.*x);
Z = @(x,y,z)(y+z);
This will make calling them inside the function consistent, and make the function more versatile.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Calendar 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by