Can someone help me with my programs logic?

2 次查看(过去 30 天)
I wrote this program which shows a graph in 4 subplots, each with a different view. then the program finds the min and max of the grid. I'm trying to create a flow chart of the programs logic. Does anyone know the order that the program functions? Or is it as simple as whatever is typed first is executed first? Thank You
% define x ,y and z
x = -10:1:10;
y = x;
[xGrid,yGrid] = meshgrid(x,y); % creates matrices to represent x and y
z = (1./((xGrid+3).^2 + (yGrid-1).^2 + 2)) + ((xGrid-yGrid) ./ ((xGrid-1) .^2 + (yGrid-2) .^2 + 4));
subplot(2,2,1)
surf(x,y,z)
title('Isometric View') % default view is isometric
xlabel('X')
ylabel('Y')
zlabel('Z')
subplot(2,2,2)
surf(x,y,z)
az=0; % changing elevation and azimuth can change veiwing angle
el=90;
view(az,el) % tell Matlab how to view it
title('View Normal to X-Y Plane')
xlabel('X')
ylabel('Y')
zlabel('Z')
subplot(2,2,3)
surf(x,y,z)
view(0,0)
title('View Normal to X-Z Plane')
xlabel('X')
ylabel('Y')
zlabel('Z')
subplot(2,2,4)
surf(x,y,z)
az=90;
el=0;
view(az,el)
title('View Normal to Y-Z Plane')
xlabel('X')
ylabel('Y')
zlabel('Z')
% Min/NegFunction represents the notation for an anonymous function. it
% creates a function where x is vector of independant variables.
MinFunction = @(x)(1./((x(1)+3).^2 + (x(2)-1).^2 + 2)) + ((x(1)-x(2)) ./ ((x(1)-1) .^2 + (x(2)-2) .^2 + 4));
NegFunction = @(x)(-1./((x(1)+3).^2 + (x(2)-1).^2 + 2)) + ((x(1)-x(2)) ./ ((x(1)-1) .^2 + (x(2)-2) .^2 + 4));
[xyMaxVector,zMax] = fminsearch(NegFunction,[0,3]);
xMax = xyMaxVector(1);% values of x when z is max
yMax = xyMaxVector(2);% value of min when z is max
[xyMinVector,zMin] = fminsearch(MinFunction,[0,1]);
xMin = xyMinVector(1);% values of x and y when z is min
yMin = xyMinVector(2);
fprintf('The Min Value was: z(%6.3f,%6.3f) = %6.3f\n',xMin,yMin,zMin)
fprintf('The Max Value was: z(%6.3f,%6.3f) = %6.3f\n',xMax,yMax,-zMax)

回答(1 个)

Walter Roberson
Walter Roberson 2014-5-12
When there are no "if" or "for" or "while" or "break" or "continue" or "return" or "quit" or "exit", then statements are executed in sequence they appear in.

类别

Help CenterFile Exchange 中查找有关 Data Distribution Plots 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by