How can I solve these recursive equations ?

Hello I want to take the solution of a equation and use this as a new variable and so on like in the following demonstrated.
x1=a+bx0
x2=a+bx1
x3=a+bx2 ......
How can I solve this by a loop or so because I have to do this until 743 and I need every of the x values, so in the end I want to have a x matrix with 743x1 dimension.

댓글 수: 1

Stephen23
Stephen23 2016년 1월 14일
편집: Stephen23 2016년 1월 14일
Whatever you do, do not create the variable names dynamically, just save the values in a vector instead. Here is an explanation of why it is very poor programming practice to create variable names dynamically:

댓글을 달려면 로그인하십시오.

 채택된 답변

Torsten
Torsten 2016년 1월 13일

0 개 추천

xn = a*(1-b^n)/(1-b) + b^n*x0.
Now insert n=743.
Best wishes
Torsten.

댓글 수: 6

Fox
Fox 2016년 1월 13일
편집: Fox 2016년 1월 13일
Thanks. However it doesn't solve my problem. I need every of the x values at the end. I tried the following,but I always get the mistake of "Index exceeds matrix dimensions."
xb(1)=a/(1-b); % xb is a scalar , a and b also scalars
for m=1:743
x2(m+1)=a+ b*xb(m);
end
Do you see my mistake here or anybody else ?
x = zeros(743);
x(1)=a/(1-b); % xb is a scalar , a and b also scalars
for m=1:742
x(m+1)=a+b*x(m);
end
Best wishes
Torsten.
Well, better would have been to keep with the original formula and adjust it to work with matrices:
n = 1:743;
xn = a*(1-b.^n)/(1-b) + b.^n*x0
Fox
Fox 2016년 1월 13일
편집: Fox 2016년 1월 13일
Hi thanks with the transformed formular it works. But now I've an addttional problem. In a second step I want to adjust my a values. like in the following described.
x1=a(1,:)+bx0
x2=a(2,:)+bx1
x3=a(3,:)+bx2
a is now a vektor of 743x1 which also influences the resulting value. I tried to solve this by a loop but I get the wrong solutions.
m=1:743
for i=1:743
xm = a(i,:)*(1-b.^m)/(1-b) + b.^m*xx0;
end
The formula is only valid for constant a. For a depending on n you will have to refer to the loop solution from above:
x(1) = some value;
for m=1:742
x(m+1)=a(m+1)+b*x(m);
end
Best wishes
Torsten.
Fox
Fox 2016년 1월 15일
Thank you very much.

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Guillaume
Guillaume 2016년 1월 14일

0 개 추천

The filter function allows you to compute all your elements in one go for both use cases (a constant or variable):
  • constant a and b:
numelemrequired = 743;
x = filter(1, [1 -b], [x0 repmat(a, 1, numelemrequired)])
  • variable a and b:
x = filter(1, [1 -b], [x0 a]) %where a is a vector of length 743
Note that your a, b, and x are not the same a, b, and x used by the documentation of filter.

카테고리

도움말 센터File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

질문:

Fox
2016년 1월 13일

댓글:

Fox
2016년 1월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by