how to plot 2 curve with together

8 vues (au cours des 30 derniers jours)
saman ahmadi
saman ahmadi le 5 Août 2020
Commenté : saman ahmadi le 5 Août 2020
Hi. i want to plot below the eqs. in matlab. i want to plot f and f1 with together in one graph and then g and g1 with together in another graph. thank you
m=0:0.01:50;
f= ((7*m - 7*(m.^2 - (226*m)/7 + 15009/49).^(1/2) + 127)/(7*(3*m + 1))).^(1/2);
f1= (2.^(1/2)*((3*m + 1)*(m + 1)).^(1/2))/(3*m + 1);
g=((7*m + 7*(m.^2 - (226*m)/7 + 15009/49).^(1/2) + 127)/(7*(3*m + 1))).^(1/2);
g1=-(2^(1/2)*((3*m + 1)*(m + 1)).^(1/2))/(3*m + 1);
  3 commentaires
saman ahmadi
saman ahmadi le 5 Août 2020
I want to draw these equations as I said in the previous message. But I can not please help me. Thankful
Adam Danz
Adam Danz le 5 Août 2020
Why can't you?
Because of an error message?
Because you don't know what functions to use?
We can't help you if we don't understand what the problem is.

Connectez-vous pour commenter.

Réponses (3)

Star Strider
Star Strider le 5 Août 2020
First, use element-wise multiplication and division:
m=0:0.01:50;
f= ((7*m - 7*(m.^2 - (226*m)/7 + 15009/49).^(1/2) + 127)./(7*(3*m + 1))).^(1/2);
f1= (2.^(1/2)*((3*m + 1).*(m + 1)).^(1/2))./(3*m + 1);
g=((7*m + 7*(m.^2 - (226*m)/7 + 15009/49).^(1/2) + 127)./(7*(3*m + 1))).^(1/2);
g1=-(2^(1/2)*((3*m + 1).*(m + 1)).^(1/2))./(3*m + 1);
Then to plot them:
figure
subplot(2,1,1)
plot(m, [f; f1])
legend('f','f1')
grid
subplot(2,1,2)
plot(m, [g; g1])
legend('g','g1')
grid
If you want them in separate figures:
figure
plot(m, [f; f1])
legend('f','f1')
grid
figure
plot(m, [g; g1])
legend('g','g1')
grid
.
  1 commentaire
saman ahmadi
saman ahmadi le 5 Août 2020
thank you very much

Connectez-vous pour commenter.


Adam Danz
Adam Danz le 5 Août 2020
The code results in the error,
Error using *
Incorrect dimensions for matrix multiplication. Check that the number of columns in the
first matrix matches the number of rows in the second matrix. To perform elementwise
multiplication, use '.*'.
However there are several other errors to address.
First error
The error is happening here in f1
(3*m + 1)*(m + 1)
because you're multiplying a [1x5001] vector by [1x5001] which disobeys matrix multiplication rules.
If you want to multiply those values piece-wise, you'll need to use ".*"
(3*m + 1).*(m + 1)
% ^
If you want to use matrix multiplication,
(3*m + 1).*(m + 1).'
% ^^
Second error
The same error is in g1. Now you know how to fix that.
Errors 3-5
Judging by you description, it seems that you expect the results to be vectors. The two corrections above will produce scalar values because the division marked below is matrix-division rather than element-wise division. Use "./" instead.
f= ((7*m - 7*(m.^2 - (226*m)/7 + 15009/49).^(1/2) + 127)./(7*(3*m + 1))).^(1/2);
% ^
The same is true for f1, g, and g1. Now you know how to fix that.
  1 commentaire
saman ahmadi
saman ahmadi le 5 Août 2020
thank you very much

Connectez-vous pour commenter.


Rik
Rik le 5 Août 2020
doc hold
doc subplot
Or even the documentation of plot itself: direct link.

Catégories

En savoir plus sur Interpolation of 2-D Selections in 3-D Grids dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by