MATLAB Answers

Using 3 dimensional array to 2d-plot????

22 views (last 30 days)
Nitesh on 30 Sep 2015
Commented: arich82 on 30 Sep 2015
I need to use this 3 arrays into 2 equations to 2d-plot
the equation is given below
code for the above equation is given below
all the three array need to used together into the equation and get plot as the graph given below
How can i use the 3 dimensional array to plot the graph above.. please help me or suggest me some hints.
Thank you.

Answers (2)

Star Strider
Star Strider on 30 Sep 2015
At the very least you need to vectorise your equations to get vectors of ‘ki’ and ‘kp’:
You did not provide ‘pmr’, and the values for your variables (and your equations) will not give you the full loop in the image. I leave that to you to sort out.
Star Strider
Star Strider on 30 Sep 2015
I have no idea why your code is not reproducing the 2D plot you posted. (I have no idea what you are even doing.) I vectorised your ‘kp’ and ‘ki’ assignments and got them to work.
I must leave it to you to be sure they — and the rest of your code — are otherwise correct.

Sign in to comment.

arich82 on 30 Sep 2015
Edited: arich82 on 30 Sep 2015
At the very least, you need to switch your i=i+1 and k=k+1 statements: you have k indexing the inner-most loop, and i indexing the outer-most, but the increments are swapped. You also need to change ki in you statement for kp to ki(i, j, k).
You might also want to try plotting using
plot(ki(:), kp(:), '.')
I'm not sure this is going to give you what you want. I'm pretty sure that a fair number of your roughly 1 million data points will be inf and NaN...
Consider the following, which should be equivalent:
n = 100;
omega = linspace(0, 100, n + 1);
mu = linspace(0, 1, n + 1);
lambda = linspace(0, 1, n + 1);
[Omega, Mu, Lambda] = ndgrid(omega, mu, lambda);
K_i = -(...
-(Omega.^(3 + Lambda)) + ...
42.46*(Omega.^(1 + Lambda)) + ...
100*(Omega.^(Lambda + Mu)).*sin(Mu*pi/2)...
K_p = -(...
-(Omega.^(3 + Lambda)).*cos((1 + Lambda)*pi/2) + ...
42.46*(Omega.^(1 + Lambda)).*cos((1 + Lambda)*pi/2) + ...
-15.88*(Omega.^(2 + Lambda)).*cos(Lambda*pi/2) + ...
106.2*(Omega.^(Lambda)).*cos(Lambda*pi/2) + ...
100*(Omega.^(Lambda + Mu)).*cos((Lambda + Mu)*pi/2) + ...
250*K_i ...
figure; plot(K_p(:), K_i(:), '.')
It would appear that you're trying to plot the stability regions for a PID controller. I'm not sure this is the best approach...
arich82 on 30 Sep 2015
Note: I appear to have made an error in my first post: the expression for K_i has a leading negative sign which shouldn't be there.
(This also invalidates the values for K_p, and both plots, but the comments about the inf and NaN, the parametric nature of the plot, and the suggested range for omega still stand.)

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by