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?
0 件のコメント
回答 (1 件)
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
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Loops and Conditional Statements についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!