Matlab function input define

6 Ansichten (letzte 30 Tage)
Moli Wang
Moli Wang am 29 Mär. 2017
Bearbeitet: Walter Roberson am 30 Mär. 2017
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?

Antworten (1)

Richard Zappulla
Richard Zappulla am 30 Mär. 2017
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 Kommentar
Stephen23
Stephen23 am 30 Mär. 2017
Bearbeitet: Stephen23 am 30 Mär. 2017
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.

Melden Sie sich an, um zu kommentieren.

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by