Hello everyone! I am new to MATLAB and kinda unexperienced and i need your help for a script! I'm trying to obtain the values of y and y1 of the script bellow! In command window i receive the values but i can't plot them right or seing them as an array in workspace but only seperated. Can anyone please tell me where am i wrong? Thank you!
x=[0:0.1:1];
for i=0:0.1:1
y=2*(-88404*i*(1-i)*(6*(i-1)-4.1*i))/(12640.5*(1-i)+16860*((6-4.1)*i-6)*(-2)*(((4.1-6)*i)+6)+618272*(i^2))
x1=i;
y1=(-105258*i*(1-i))/(69126*i+101160*(1-i)-12640.5*(1-i))
end
plot (x,y,'o')

 채택된 답변

David Fletcher
David Fletcher 2021년 5월 16일

0 개 추천

you need to retain the values of y as you go through each iteration of the loop. There are a few ways of doing it, but perhaps the quick and dirty way in the context of your loop is:
x=[0:0.1:1];
y=[];
for i=0:0.1:1
y=[y 2*(-88404*i*(1-i)*(6*(i-1)-4.1*i))/(12640.5*(1-i)+16860*((6-4.1)*i-6)*(-2)*(((4.1-6)*i)+6)+618272*(i^2))]
x1=i;
y1=(-105258*i*(1-i))/(69126*i+101160*(1-i)-12640.5*(1-i))
end
plot (x,y,'o-')

댓글 수: 3

Alex T.
Alex T. 2021년 5월 16일
Thank you very much for the answer David ! It works! So can i plot also the y1 value this way? I mean for the same values of x to obtain the relative y1 values? Thank you again!
David Fletcher
David Fletcher 2021년 5월 16일
Yes, you can use the same strategy for y1
Alex T.
Alex T. 2021년 5월 16일
Thank you very much David! Really appreciate it! Wish you all the best for the future!

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

2021년 5월 16일

댓글:

2021년 5월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by