Formatting an equation such as f(x1)+f(x2​)*(t-x1)+f​(x3)*(t-x1​)(t-x2)

1 visualización (últimos 30 días)
Gina DiCarlo
Gina DiCarlo el 10 de Oct. de 2016
Respondida: Eamon el 10 de Oct. de 2016
In the equation I already have everything found so let's say y1 = f(x1), y2 = f(x2), and d1 = (t-x1), d2 = (t-x2)...
I don't know how to format a loop so that I can have y1 +y2*d1 + y3*d1*d2?

Respuestas (1)

Eamon
Eamon el 10 de Oct. de 2016
First, you would initialize variables, then you could structure a for or while loop using the desired looping conditions. In this example below, every time the code progresses through the loop, t is increased by 1, so this for loop will loop through 99 times. You have to decide whether a for loop or a while loop would better suit your purposes. For loops run for a specific number of times, and while loops run as long as some condition is true. You can read more about for/while loops here .
t=1;
x1=[];
x2=[];
y1=f(x1);
y2=f(x2);
d1=(t-x1);
d2=(t-x2);
while t< 100
answer=y1+y2*d1+y3*d1*d2
t=t+1;
end

Categorías

Más información sobre Loops and Conditional Statements en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by