Formatting an equation such as f(x1)+f(x2)*(t-x1)+f(x3)*(t-x1)(t-x2)
1 view (last 30 days)
Show older comments
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 Comments
Answers (1)
Eamon
on 10 Oct 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
0 Comments
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!