how to make fuction from changing varibles

조회 수: 1 (최근 30일)
tal shmuel
tal shmuel 2020년 1월 16일
댓글: Star Strider 2020년 1월 16일
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