Producing arrays to plot (MATLAB)

In summary, you would need to concatenate the p, q and eq values into one vector, then use the 'reshape' command to reshape the vector into the correct form for plotting.
  • #1
Liffner
2
0
Hi everyone, my code is a little rusty and a work in progress but I was wondering how I would go about producing arrays for the calculations performed in the while loop for the analyses so they can be plotted.

I have the following parameter input;
G0 = 50;
v = 0.25;
M = 1.305;
elim = 0.92;
Gamma = 0.0375;
xi = 0.6;
Pa = 101;
h1 = 4.45;
h2 = 4.2;
n = 1;
d0 = 1;
m = 0.5;

p01 = input('Give value for p0(1) =')
q01 = input('Give value for qo(1) =')
e01 = input('Give value for e0(1) =')
p02 = input('Give value for p0(2) =')
q02 = input('Give value for qo(2) =')
e02 = input('Give value for e0(2) =')
p03 = input('Give value for p0(3) =')
q03 = input('Give value for qo(3) =')
e03 = input('Give value for e0(3) =')

eq = deq0*100;
while eq < 40
eq = eq + deq0*100;
% For the first analysis
Psi1 = e01-(elim-Gamma*(p01/Pa)^xi);
eta1 = q01/p01;
G1 = G0*(((2.97-e01)^2)/(1+e01))*(sqrt(p01*Pa));
K1 = G1*((2*(1+v))/(3*(1-2*v)));
d1 = d0*(exp(m*Psi1)-(eta1/M));
kp1 = (h1-h2*e01)*G1*((M/eta1)-exp(Psi1*n));
dq1 = (-kp1*deq0/eta1*(d1*eta1/kp1-1/K1))/(d1/kp1-(d1*eta1/kp1-1/K1)*kp1/eta1*(1/(3*G1)+1/kp1));
dp1 = kp1/eta1*((1/(3*G1)+1/kp1)*dq1-deq0);
p01 = p01 + dp1;
q01 = q01 + dq1;
% For the second analysis
Psi2 = e02-(elim-Gamma*(p02/Pa)^xi);
eta2 = q02/p02;
G2 = G0*(((2.97-e02)^2)/(1+e02))*(sqrt(p02*Pa));
K2 = G2*((2*(1+v))/(3*(1-2*v)));
d2 = d0*(exp(m*Psi2)-(eta2/M));
kp2 = (h1-h2*e02)*G2*((M/eta2)-exp(Psi2*n));
dq2 = (-kp2*deq0/eta2*(d2*eta2/kp2-1/K2))/(d2/kp2-(d2*eta2/kp2-1/K2)*kp2/eta2*(1/(3*G2)+1/kp2));
dp2 = kp2/eta2*((1/(3*G2)+1/kp2)*dq2-deq0);
p02 = p02 + dp2;
q02 = q02 + dq2;
% For the third analysis
Psi3 = e03-(elim-Gamma*(p03/Pa)^xi);
eta3 = q03/p03;
G3 = G0*(((2.97-e03)^2)/(1+e03))*(sqrt(p03*Pa));
K3 = G3*((2*(1+v))/(3*(1-2*v)));
d3 = d0*(exp(m*Psi3)-(eta3/M));
kp3 = (h1-h2*e03)*G3*((M/eta3)-exp(Psi3*n));
dq3 = (-kp3*deq0/eta3*(d3*eta3/kp3-1/K3))/(d3/kp3-(d3*eta3/kp3-1/K3)*kp3/eta3*(1/(3*G3)+1/kp3));
dp3 = kp3/eta3*((1/(3*G3)+1/kp3)*dq3-deq0);
p03 = p03 + dp3;
q03 = q03 + dq3;
end

Essentially, I would like to plot the corresponding p, q and eq for each analysis but with the way it is currently set out, it is only producing 1 number for each.
Any help will be appreciated. I haven't used the program in a few years so forgive my poor layout.
 
Physics news on Phys.org
  • #3
Thanks, will give that a try.
 

1. How do I create a basic plot in MATLAB?

To create a basic plot in MATLAB, you can use the "plot" function. This function takes in two arrays as inputs - one for the x-axis values and one for the y-axis values. For example, if you want to plot the points (1, 2), (3, 4), and (5, 6), you can use the code "plot([1, 3, 5], [2, 4, 6])".

2. How do I customize the appearance of my plot?

To customize the appearance of your plot, you can use various optional arguments in the "plot" function. For example, you can change the color and style of the line by using the "Color" and "LineStyle" arguments. You can also add a title, label the axes, and add a legend using the "title", "xlabel", "ylabel", and "legend" functions respectively.

3. Can I plot multiple lines on the same graph?

Yes, you can plot multiple lines on the same graph by using the "hold on" and "hold off" commands. The "hold on" command allows you to add multiple plots to the same figure, while the "hold off" command stops this behavior.

4. How do I save my plot as an image?

To save your plot as an image, you can use the "saveas" function. This function takes in the figure handle and the desired file name as inputs. You can also specify the file type by using the appropriate file extension, such as ".png" or ".jpg".

5. How can I create different types of plots, such as bar graphs or scatter plots?

MATLAB offers a variety of different functions for creating different types of plots. For example, you can use the "bar" function to create a bar graph, the "scatter" function to create a scatter plot, or the "histogram" function to create a histogram. These functions also have optional arguments for customizing the appearance of the plot.

Back
Top