How to plot recursive function/how to avoid infinite recursion?

Hey there
Im trying to plot the following equation
a(n+1)=a(n)+b(n+1)*0.0215
where
b(n+1)=b(n)+(9.81/0.94)*sin(a(n))*0.0215
a(0)=65
b(0)=0
Is it possible to plot the first line as a graph in Matlab, untill a reaches reaches 65 again (should be a U shaped curve)?
I've tried a few things but the error message tells me there is an infinite recursion.
Any help is greatly appriciated.

댓글 수: 1

"I've tried a few things but the error message tells me there is an infinite recursion."
Please share your code you have written yet.

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

답변 (1개)

a(1) = 65;
b(1)= 0;
i = 1;
while a(i)>a(1) || i==1
b(i+1) = b(i) + 9.81/0.94*sin(a(i))*0.0215;
a(i+1) = a(i) + 0.0215*b(i+1);
i = i+1;
end
plot(a)

댓글 수: 2

Thank you so much!
Florian Bidaud
Florian Bidaud 2023년 11월 21일
편집: Florian Bidaud 2023년 11월 21일
You're welcome ! Please accept the answer if you're happy with it :)

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

카테고리

도움말 센터File Exchange에서 Logical에 대해 자세히 알아보기

제품

질문:

2023년 11월 21일

편집:

2023년 11월 21일

Community Treasure Hunt

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

Start Hunting!

Translated by