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

I need to use this 3 arrays into 2 equations to 2d-plot
w=0:1:100;
mu4=0:0.01:1;
lam4=0:0.01:1;
the equation is given below
code for the above equation is given below
th1=cos(lam4*(pmr/2));
th2=cos((1+lam4)*(pmr/2));
th3=cos((lam4+mu4)*(pmr/2));
th4=sin(mu4*(pmr/2));
th5=sin(lam4*(pmr/2));
ki=((-w^(3+lam4))+(42.46*(w^(1+lam4)))+(100*w^(mu4+lam4)*th4))/(250*th5)
kp=(-1/(250*(w^lam4)*th1))*(((-w^(3+lam4))*th2)+((42.46*w^(1+lam4))*th2)...
-(15.88*(w^(2+lam4))*th1)+(106.2*(w^lam4)*th1)+(100*(w^(lam4+mu4))*th3)...
+250*ki)
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.
Nitesh

回答(2 个)

At the very least you need to vectorise your equations to get vectors of ‘ki’ and ‘kp’:
ki=((-w.^(3+lam4))+(42.46*(w.^(1+lam4)))+(100*w.^(mu4+lam4).*th4))./(250*th5);
kp=(-1./(250*(w.^lam4).*th1)).*(((-w.^(3+lam4)).*th2)+((42.46*w.^(1+lam4)).*th2)...
-(15.88*(w.^(2+lam4)).*th1)+(106.2*(w.^lam4).*th1)+(100*(w.^(lam4+mu4)).*th3)...
+250*ki);
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.

4 个评论

Hello
pmr = 180 which is the pi value.
This is my codes im working on.
clear all; close all; clf; clc
%Fractional Order PID
i=1;
j=1;
k=1;
pmr=180; %Value of PI
i=1;
for w=0:1:100; % Omega Value Set Range
j=1;
for mu4=0:0.1:1; % Mu Value Set Range
k=1;
for lam4=0:0.1:1; % Lambda Value Set Range
% Short Hand calcalution for Theta values of cos and sin
th1=cos(lam4*(pmr/2));
th2=cos((1+lam4)*(pmr/2));
th3=cos((lam4+mu4)*(pmr/2));
th4=sin(mu4*(pmr/2));
th5=sin(lam4*(pmr/2));
ki(i,j,k)=((-w^(3+lam4))+(42.46*(w^(1+lam4)))+(100*w^(mu4+lam4)*th4))/(250*th5)
kp(i,j,k)=(-1/(250*(w^lam4)*th1))*(((-w^(3+lam4))*th2)+((42.46*w^(1+lam4))*th2)...
-(15.88*(w^(2+lam4))*th1)+(106.2*(w^lam4)*th1)+(100*(w^(lam4+mu4))*th3)...
+250*ki)
i=i+1; % for next update
end % End loop for Lambda
j=j+1; % for next update
end % End loop for mu
k=k+1; % for next update
end % End loop for Omega
figure(1)
plot(ki,kp,'r', 'Linewidth',0.5)
Im using the above coding using 3 dimensional array for loop. However, im having a error which i cant resolve..
Assignment has more non-singleton rhs dimensions than non-singleton subscripts
Your help will be appreciated. Thank you.
Nitesh
The impression I get is that you are calculating ‘kp’ and ‘ki’ from your three vectors, then plotting them:
plot(ki, kp)
The plot you show is not a surface plot.
Yes im calculating kp and ki from the 3 vectors. But the loop isnt working as expected. I need help to operate the loop to obtain values. Can you suggest me on my codes i have provided??
Thnk you
Nitesh
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.

请先登录,再进行评论。

arich82
arich82 2015-9-30
编辑:arich82 2015-9-30
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)...
)./(250*sin(Lambda*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 ...
)./(250*(Omega.^Lambda).*cos(Lambda*pi/2));
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...

2 个评论

Looking more closely at your (updated) problem, the plot you show (Figure 5) that indicates that mu and lambda are fixed in the plot ( 1.15 and 0.9, respectively). I assume that means the plot in the figure is essentially a parametric plot as a function of omega.
However, it doesn't seem like fixing these values in the code above reproduces the plot, though I might have made a mistake...
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.)

请先登录,再进行评论。

类别

帮助中心File Exchange 中查找有关 2-D and 3-D Plots 的更多信息

产品

提问:

2015-9-30

评论:

2015-9-30

Community Treasure Hunt

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

Start Hunting!

Translated by