how to plot 2 curve with together
1 次查看(过去 30 天)
显示 更早的评论
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 个评论
Adam Danz
2020-8-5
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.
回答(3 个)
Star Strider
2020-8-5
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
2020-8-5
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!