MATLAB plot is blank?

조회 수: 21 (최근 30일)
Holli Sharples
Holli Sharples 2021년 9월 22일
답변: Image Analyst 2021년 9월 22일
I have to set two functions r and q, with a as the independent variable, on a graph together. I must plot both functions, where function r is on the y axis and function q is on the y axis. Both functions r and q have been solved for by hand and are given as correct. However, when I try to plug this code into MATLAB, my plots show up blank, even after I limit my x and y ranges to the desired limits. I am also very new to MATLAB and am still trying to learn so I'm unfamiliar with complicated code. If someone could explain how to produce this, it woud be extremely helpful.
This is what we are supposed to produce: (r function vs q function) (r=y axis, q=x axis)
My code is as follows (I tried a lot of different plot functions to get a single graph, but nothing appeared for any of them):
a1=0:0.1:100
r=(2*a1.^3)/((1+a1.^2).^2)
q=(2*a1.^3)/((a1.^2)-1)
plot(a,r)
plot(a,q)
plot(q,r)
xlim([0 100])
ylim([0 0.8])

채택된 답변

Stephen23
Stephen23 2021년 9월 22일
편집: Stephen23 2021년 9월 22일
You are using matrix division where you should be using array division:
and you need to use HOLD ON after the first PLOT call, or just use one PLOT call:
a = 0:0.1:100;
r = (2*a.^3)./((1+a.^2).^2);
q = (2*a.^3)./((a.^2)-1);
plot(a,r, a,q, q,r)
xlim([0,100])
ylim([0,0.8])

추가 답변 (1개)

Image Analyst
Image Analyst 2021년 9월 22일
Here's a version where you use hold on. I also show you how you can use a legend, change the line width, and attach descriptive axis labels:
a1=0:0.1:100
r=(2*a1.^3) ./ ((1+a1.^2).^2);
q=(2*a1.^3) ./ ((a1.^2)-1);
% Make "a" variable. Assume it's the same as a1.
a = a1;
plot(a, r, 'LineWidth', 2)
hold on;
plot(a, q, 'LineWidth', 2)
plot(q, r, 'LineWidth', 2)
grid on;
legend('r vs a', 'q vs a', 'r vs q');
xlim([0 100])
ylim([0 0.8])
xlabel('a or q', 'FontSize', 15);
ylabel('r or q', 'FontSize', 15);

카테고리

Help CenterFile Exchange에서 Line Plots에 대해 자세히 알아보기

태그

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by