how to plot 2 curve with together
조회 수: 2 (최근 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!