I have an equation (a-b)x+(c-b)y <= d and i would like to plot 20 instances of this equation.
The limits of the plot are set from -5 to 5. I have already a set of values for the a,b,c,d
Any ideas?
My code so far is:
x = [-5:0.1:5];
L = 20;
hold off
for i=1:L
y = (d-x*(a-b))/(c-b)
plot(x,y)
hold on
end

댓글 수: 1

Gani
Gani 2019년 6월 28일
편집: Gani 2019년 6월 28일
You are not changing the values of Y inside the loop. Hence you will get same plot in each iteration.

댓글을 달려면 로그인하십시오.

답변 (1개)

Star Strider
Star Strider 2019년 6월 28일

1 개 추천

You do not need the loop.
Try this:
x = linspace(-5, 5, 20);
L = 20;
y = (d-x*(a-b))/(c-b);
plot(x,y)

댓글 수: 4

Jack Haratsi
Jack Haratsi 2019년 6월 28일
Thank you for your answer but I think i expressed my question wrong.
The variables a,b,c,d are described by vectors of 20 elements each.
For each x,y variable, the equation should be given by a line in an x,y plot and that's why i used the loop.
The x,y are to be ploted in order to graph the blue lines showcased below:
Annotation 2019-06-28 162333.png
Star Strider
Star Strider 2019년 6월 28일
My pleasure.
Yes, you did.
Knowing what a, b, c, and d are, and how they relate to the lines you want to plot, would help immensely. Are they the respective ends of the lines? Are they slopes and intercepts? Something else?
Jack Haratsi
Jack Haratsi 2019년 6월 28일
They should be the ends of the lines. They should be treated as ''constraints'' that determine the domain at which i have a feasible solution.
Right now, my plot looks something like that, and i am not sure if it is correct:
untitled.jpg
Star Strider
Star Strider 2019년 6월 28일
편집: Star Strider 2019년 6월 28일
What are the ends of the lines?
How should the lines be defined in terms of a, b, c, and d?
EDIT —
Should they be plotted as:
plot([a(:) b(:)]', [c(:) d(:)]')
Note that this will produce the series of straight lines that you likely want. The question is how to assign the vectors to the matrices here.

댓글을 달려면 로그인하십시오.

카테고리

도움말 센터File Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

질문:

2019년 6월 28일

편집:

2019년 6월 28일

Community Treasure Hunt

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

Start Hunting!

Translated by