how to plot 2 curve with together
2 views (last 30 days)
Show older comments
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 Comments
Adam Danz
on 5 Aug 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.
Answers (3)
Star Strider
on 5 Aug 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
.
Adam Danz
on 5 Aug 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.
See Also
Categories
Find more on Interpolation of 2-D Selections in 3-D Grids in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!