How to use loop and solve numerical question and make variable with numerical variables

I'm relatively new to matlab and would appreciate some advice on how to use the for loop function.
What I want to accomplish: create a variable including the numerical values solved by a simple equation in a loop. The math is pretty simple- forward euler method- but I don't know how I would set this up in a loop- if that's even possible. (I know this can be done in excel... So I imagine it can be done in matlab...)
Variables: CFC0 %initial value of CFC; given (2.9e11) dt=3.5 k=35
In essence, this is what I want (29 times):
CFC1= cfc0 +k*cfc0*dt;
CFC2= CFC1 +k*CFC1*dt;
CFC3= CFC2 +k*CFC2*dt;
But I want all of the CFC outputs to be organized into a column (or row) of a new variable CFC_100.
I don't know how to start this, and would be grateful for any hints!

1 comentario

A Jenkins
A Jenkins el 21 de Mayo de 2014
Editada: A Jenkins el 21 de Mayo de 2014
(You might want to double check the equations for forward euler, but I gave you help on for loops below, since that is what you asked.)

Iniciar sesión para comentar.

 Respuesta aceptada

Here is a hint on using for loops:
x(1)=1;
for index=1:10
x(index+1)=x(index)+x(index)*10;
end
disp(x)
You'll obviously need to change some of this code, but that is how you will learn!

Más respuestas (0)

Preguntada:

el 21 de Mayo de 2014

Editada:

el 21 de Mayo de 2014

Community Treasure Hunt

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

Start Hunting!

Translated by