Calculate an expression in MAtlab

(Sorry i don't know a better title)
I have (n=0,1,2,3,....)
How can I calculate the below expression with matlab codes ?
Thank you

 Accepted Answer

It depends on what ‘T’ and ‘c’ are.
If they are scalars, this would likely work:
T = rand;
c = rand;
x(1) = rand;
N = 10;
for k = 1:N
x(k+1) = x(k)*T+c;
end

2 Comments

Is there any way I can type x(0) instead of x(1) ?
T = 1;
c = 2;
X(0)= 3;
N = 10;
for k = 1:N
X(k) = X(k-1)*T+c;
end
If I correct the codes like this, an error appears :"Array indices must be positive integers or logical values."
‘Is there any way I can type x(0) instead of x(1) ?’
Not in MATLAB. In MATLAB, indices must be integers greater than 1.
However you can choose to display them the way you want:
for k = 1:numel(x)
fprintf('x(%d) = %.4f\n', k-1, x(k))
end
producing:
x(0) = 0.6905
x(1) = 1.0766
x(2) = 1.2961
...

Sign in to comment.

More Answers (0)

Categories

Find more on Get Started with MATLAB in Help Center and File Exchange

Products

Tags

Community Treasure Hunt

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

Start Hunting!