# how to make fuction from changing varibles

3 views (last 30 days)
tal shmuel on 16 Jan 2020
Commented: Star Strider on 16 Jan 2020
hello everyone !
in my graduate of mechanical engeneering , i need to test function with 3-5 varibles.
the problem that all varibles are nedd to change and finally i need to take tha value of my function
i have differnet boundries for each varible. for example :
Z(a,b,c)
a - angle, between 0 to pi [rad[
b - distance, between 440 to 3010 [mm]
c - load, between 0-4000 [N]
i need to test Z function in al the combinations between the varibles, finally i need to test my function at the max value ans in the min value.
how can i do it ?
tal shmuel

Star Strider on 16 Jan 2020
That is relatively straightforward to do with ndgrid or meshgrid.
Try this hypothetical example:
Z = @(x,y,z) x.^2 + y.^2 + z.^2; % Create ‘Z’
a = linspace(0, pi, 5); % Define Vector
b = linspace(440, 3010, 4); % Define Vector
c = linspace(0, 4000, 3); % Define Vector
[A,B,C] = ndgrid(a,b,c); % Create Matrices From Vectors
Zout = Z(A(:),B(:),C(:)); % Creates Appropriate Column Vectors For All Elements Of Original Vectors
[Zmax,ixmx] = max(sum(Zout,2));
[Zmin,ixmn] = min(sum(Zout,2));
Use your own ‘Z’ and your own method of assessing its values.

tal shmuel on 16 Jan 2020
can i make from all results kinds of 3D graphs ?
Star Strider on 16 Jan 2020
That depends.
If you choose two independent variables and the output of ‘Z’, then probably: Yes.
From my example here:
Z = @(x,y,z) x.^2 + y.^2 + z.^2; % Create ‘Z’
a = linspace(0, pi, 5); % Define Vector
b = linspace(440, 3010, 4); % Define Vector
c = linspace(0, 4000, 3); % Define Vector
[A,B,C] = ndgrid(a,b,c); % Create Matrices From Vectors
Zout = Z(A(:),B(:),C(:)); % Creates Appropriate Column Vectors For All Elements Of Original Vectors
[Zmax,ixmx] = max(sum(Zout,2));
[Zmin,ixmn] = min(sum(Zout,2));
Av = A(:);
Bv = B(:);
Zv = Zout(:);
figure
stem3(Av, Bv, Zv,'.')
grid on
Since 3D plots are restricted to 3 dimensions, only some combinations of variables and the function output are possible.