how to make fuction from changing varibles

1 次查看(过去 30 天)
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 ?
thanks about the helping
tal shmuel

回答(1 个)

Star Strider
Star Strider 2020-1-16
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.
  2 个评论
tal shmuel
tal shmuel 2020-1-16
can i make from all results kinds of 3D graphs ?
Star Strider
Star Strider 2020-1-16
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.

请先登录,再进行评论。

类别

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

标签

产品

Community Treasure Hunt

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

Start Hunting!

Translated by