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

3 Ansichten (letzte 30 Tage)
Studentguy
Studentguy am 21 Nov. 2023
Bearbeitet: Florian Bidaud am 21 Nov. 2023
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 Kommentar
Dyuman Joshi
Dyuman Joshi am 21 Nov. 2023
"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.

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Florian Bidaud
Florian Bidaud am 21 Nov. 2023
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 Kommentare
Florian Bidaud
Florian Bidaud am 21 Nov. 2023
Bearbeitet: Florian Bidaud am 21 Nov. 2023
You're welcome ! Please accept the answer if you're happy with it :)

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu 2-D and 3-D Plots finden Sie in Help Center und File Exchange

Produkte

Community Treasure Hunt

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

Start Hunting!

Translated by