PDA

View Full Version : Matlab



Cuddly
2008-02-18, 05:32 AM
I'm using matlab, and I'm currently at a total loss of how to set up a loop so for every value I generate with an equation will be used to calculate the next value of the equation.

Help!

Solo
2008-02-18, 08:08 AM
May I ask why you'd do that?

Illiterate Scribe
2008-02-18, 08:16 AM
Plotting a difficult series?

Jack Squat
2008-02-18, 08:17 AM
Ok, I don't use Matlab...but looking at a site (http://ef.engr.utk.edu/ef105-2007-08/modules/matlab-control/), it's not too different from C++.

You store the value of the equation as a variable ( c = sqrt(a*a+b*b) or something like that).

To make the previous value to go into the equation, just put it in the equation (x = x+1).

EDIT: didn't bring the loop into the equation. The loop would really just have conditions set (while (x < 10) for example).

Cuddly
2008-02-18, 09:44 AM
I'm doing it for great justice!!!
Nah, I have to do this genetics stuff for a genetics class, and cranking it by hand would be a nightmare.

I just want to know if anyone knows the template I could mess around with that gives me what I want. Or even could talk computerese to me. I don't really get code or programming languages.

Ryshan Ynrith
2008-02-18, 10:37 AM
Ah, Matlab.

Okay, there are several types of loops you can use. The most common are For loops and While loops. A For loop goes something like this (and remember to initialize all your variables; set them equal to a initial value before the loop)

x=0

For i=1:10
x=x^2+1
End

That's really all there is to it. You can replace the function with whatever you need.

While loops are used thusly, though there are many different ways to implement them.

While x>250
x=x^2 + 1
End