How to write for and while loops with restricted variable input with steps in function?

Dear Friends,
Could you tell me how to write for and while loops with restricted variable input with steps in function?
For instance;
-2<=x<=2
step:0.1
f(x)=((x^3+9)+(x^2-4))/(x*7+5))
so how can I write it to run properly and to make plot?

답변 (1개)

Adam
Adam 2016년 10월 18일
편집: Adam 2016년 10월 18일
x = -2:0.1:2;
f = ( x.^3 + 9 + x.^2 - 4 ) ./ ( x*7 + 5 );
figure; plot( x, f )
You don't need loops at all. Matlab is built for vectorisation.

이 질문은 마감되었습니다.

질문:

2016년 10월 18일

마감:

2021년 8월 20일

Community Treasure Hunt

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

Start Hunting!

Translated by