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

1 次查看(过去 30 天)
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?

回答(1 个)

Eamon
Eamon 2016-10-10
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

类别

Help CenterFile Exchange 中查找有关 Operating on Diagonal Matrices 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by