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 で Interpolation of 2-D Selections in 3-D Grids についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!