Hi everyone,
Trying to plot a graph unsucssesfully :((
alpha=2.2;
Mx0=34.8262;
My0=15.7563;
Mx=linspace(0,50,0.0001);
Interaction_Curve=(Mx./Mx0).^alpha+(My./My0).^alpha-1
plot(Interaction_Curve,Mx)
Thank You Very much

2 comentarios

madhan ravi
madhan ravi el 24 de Dic. de 2019
You didn’t define My and you haven’t used the linspace() properly for Mx.
Shimon Katzman
Shimon Katzman el 24 de Dic. de 2019
Editada: Shimon Katzman el 24 de Dic. de 2019
So what is the correct way?

Iniciar sesión para comentar.

 Respuesta aceptada

Star Strider
Star Strider el 24 de Dic. de 2019

1 voto

One problem is that ‘My’ is missing. Beyond that, the linspace arguments resulted in an empty vector for ‘Mx’.
It might be easier to plot this as an implicit function:
alpha=2.2;
Mx0=34.8262;
My0=15.7563;
Interaction_Function = @(Mx,My) (Mx./Mx0).^alpha+(My./My0).^alpha-1;
figure
fimplicit(Interaction_Function, [0 50 0 30])
ylim([0 30])
producing:
1plotting a simple Graph - 2019 12 24.png
That seems to produce the sort of plot you want. Make appropriate changes to the second agrument in the fimplicit call to get the result you want.

9 comentarios

Shimon Katzman
Shimon Katzman el 24 de Dic. de 2019
Hi Star,like always thank you so much.
The thing is that im using 2015a version and it errors me:
Undefined function or variable 'fimplicit'.
Shimon Katzman
Shimon Katzman el 24 de Dic. de 2019
i used
ezplot(Interaction_Function, [0 50 0 30])
and now it works well.
Thank you very much Star
Star Strider
Star Strider el 24 de Dic. de 2019
My pleasure.
The contour function is another option.
Try this:
alpha=2.2;
Mx0=34.8262;
My0=15.7563;
Mx=linspace(0,50,25);
My=linspace(0,50,25);
[MX,MY] = meshgrid(Mx,My);
figure
contour(Interaction_Function(MX,MY), [0 0])
That should work. The contour function has been around as long as I can remember. It should allow the definition of the single contour at [0 0] in R2015a. (This imay be what the fimpllicit function does as well. It appears to produce the same plot.)
Shimon Katzman
Shimon Katzman el 24 de Dic. de 2019
Hi Star,
Small questions for you please,
1)how do i find the intersection point between those two graphs?
2)how do i change the color of one of the graphs?
Thank YOU
alpha=2.2;
Mx0=M_x;
My0=M_y;
Mx = linspace(0,50, 1000);
My = linspace(0,50, 1000);
Interaction_Function = @(Mx,My) (Mx./Mx0).^alpha+(My./My0).^alpha-1;
figure
hold on
ezplot(Interaction_Function,[0 40 0 20])
MxdivMy = @(Mx,My) Mx-3*My;
ezplot(MxdivMy, [0 40 0 20])
grid on;
Star Strider
Star Strider el 24 de Dic. de 2019
As always, my pleasure!
I do not have ‘M_x’ and ‘M_y’, so I cannot run your latest code.
Shimon Katzman
Shimon Katzman el 24 de Dic. de 2019
Oh, im sorry.. Mx0= 34.8262 My0= 15.7563
Star Strider
Star Strider el 24 de Dic. de 2019
Not immediately obvious, so it took some time.
Try this:
alpha=2.2;
Mx0=34.8262;
My0=15.7563;
Mx=linspace(0,50,25);
My=linspace(0,50,25);
Interaction_Function = @(Mx,My) (Mx./Mx0).^alpha+(My./My0).^alpha-1;
MxdivMy = @(Mx,My) Mx-3*My;
[MX,MY] = meshgrid(Mx,My);
figure
hc1 = contour(Mx, My, Interaction_Function(MX,MY), [0 0])
hc2 = contour(Mx, My, MxdivMy(MX,MY), [0 0])
xy1 = hc1(:,2:end); % ‘Interaction Function’
xy2 = fliplr(hc2(:,2:end)); % ‘MxdivMy’
[xy2u,ix] = unique(xy2(1,:), 'stable'); % Unique ‘MxdivMy’
xy2i = interp1(xy2u(1,:), xy2(2,ix), xy1(1,:)); % Interpolate To Same x-Coordinates
xy2i = [xy1(1,:); xy2i];
xint = interp1(xy1(2,:)-xy2i(2,:), xy1(1,:), 0); % Interpolate To Find X-Intercept
yint = interp1(xy1(1,:), xy1(2,:), xint); % Interpolate To Find Y-Intercept
alpha=2.2;
% Mx0=M_x;
% My0=M_y;
Mx = linspace(0,50, 1000);
My = linspace(0,50, 1000);
Interaction_Function = @(Mx,My) (Mx./Mx0).^alpha+(My./My0).^alpha-1;
figure
hold on
ez1 = ezplot(Interaction_Function,[0 40 0 20]);
MxdivMy = @(Mx,My) Mx-3*My;
ez2 = ezplot(MxdivMy, [0 40 0 20]);
plot(xint, yint, 'pr', 'MarkerSize',10, 'MarkerFaceColor','g') % Plot Intercept
grid on;
hold off
That calculates and plots the intercept.
Shimon Katzman
Shimon Katzman el 25 de Dic. de 2019
Wow Star. Thank you so much!!
You Are The Best!
Star Strider
Star Strider el 25 de Dic. de 2019
As always, my pleasure!
I very much appreciate your compliment!

Iniciar sesión para comentar.

Más respuestas (1)

Image Analyst
Image Analyst el 24 de Dic. de 2019

0 votos

Try this:
alpha = 2.2;
Mx0 = 34.8262;
My0 = 15.7563;
Mx = linspace(0,50, 1000);
My = linspace(0,50, 1000); % Not sure what My should be!!!
Interaction_Curve = (Mx./Mx0).^alpha+(My./My0).^alpha-1
plot(Mx, Interaction_Curve, 'b-', 'LineWidth', 2)
grid on;
Be sure to define My because I just guessed incorrectly.

2 comentarios

Shimon Katzman
Shimon Katzman el 24 de Dic. de 2019
Hi, it doesnt plot the right graph :(
Image Analyst
Image Analyst el 24 de Dic. de 2019
I know. Because I don't have the value of the My variable. That's why I asked you to define it. What is it? But doesn't matter since it looks like Star figured it out.

Iniciar sesión para comentar.

Categorías

Más información sobre 2-D and 3-D Plots en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 24 de Dic. de 2019

Comentada:

el 25 de Dic. de 2019

Community Treasure Hunt

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

Start Hunting!

Translated by