How to show each iteration in for loop?
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Antonio Hamilton
am 11 Mai 2021
Kommentiert: Antonio Hamilton
am 12 Mai 2021
initialX = input('\nWhat would you like your starting x value to be?\n');
initialY = input('\nWhat would you like your starting y value to be?\n');
xo = initialX;
yo = initialY;
dydx = 0;
for j = xo:deltaxem:sizeOfGraphXPositive
xo = j;
yo = yo + (dydx .* deltaxem);
dydx = xo + yo;
plot(xo, yo, '*', 'linewidth', 4); hold on
xlim([-sizeOfGraphXPositive sizeOfGraphXPositive]);
ylim([-sizeOfGraphYPositive sizeOfGraphYPositive]);
axis equal
title("Euler's Method");
xlabel('X Values');
ylabel('Y Values');
end
2 Kommentare
James Tursa
am 11 Mai 2021
What specifically do you mean by "show each iteration"? What do you want to have happen that your current code doesn't do?
Akzeptierte Antwort
Chunru
am 12 Mai 2021
Add this after dydx=... line:
fprintf('xo = %10.5f yo = %10.5f dydx = %10.5f \n', xo, yo, dydx);
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Numeric Types finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!