Clear Filters
Clear Filters

Hello everyone! I'm a new in Matlab, but I try to do my best so I have the following task: Let's say I have an equation that I have to solve by iterative method. And also all my variables in equation are matrix. My solution has to be matrix.

1 view (last 30 days)
For example my equation A(i) = (M.*V./(B+C.*A(i-1))).^a
I know that A(1)=0, I start from i=2, and my first approximation A(2) = (M.*V./(B+C.*A(1))).^a than A(3) = (M.*V./(B+C.*A(2))).^a and etc (but I don't know my tolerance and in recommendations it's said three iterations are enough). But problem that M and V variables are matrices and C is a vector. It means first I need to take each value from each cell in matrix and iterate inside this cell. The size of my matrices let's say NxM and my result has to be a matrix NxM. I can not understand how to write the loop for these equation.
The most complicated for me is how in each iteration for defined cell use the same variables from matrices but change my I inside each cell. If I have for example three iterations for cell 1 it has to be looked like this
A(2) (1,1)= (M(1,1).*V(1,1)./(B(1,1)+C(1,1).*A(1)(1,1))).^a
A(3) (1,1)= (M(1,1).*V(1,1)./(B(1,1)+C(1,1).*A(2)(1,1))).^a
A(4) (1,1)= (M(1,1).*V(1,1)./(B(1,1)+C(1,1).*A(3)(1,1))).^a
And I need to save the last iteration A(4) and put in the first cell A(1,1) and in the end I have to get a matrix of A[NxM]
I hope I explained clearly. Thank you!
This code gives me just one value
for j=1:size1
for k=1:size2
I = zeros(size(vp));
for m=2:4
I(1)=0;
I(m) = (m5(j,k)./(m6(j,1)+m7(j,1).*I(m-1).^(a-1)./m8)).^(1/m1);
end
I(j,k)=I(m);
end
end
  4 Comments
Rachana Reddy Mamilla
Rachana Reddy Mamilla on 6 Nov 2018
vector is a matrix with either one row or one column. what do mean by V(1,1) ,are you treating it to be a matrix?
Walter Roberson
Walter Roberson on 6 Nov 2018
The poster had written "problem that M and V variables are matrices and C is a vector." so V(1,1) is quite proper.
They also use C(1,1) in their description. That is not an error, since you can have any number of extra ,1 in indices . If they had used C(1,2) or C(2,1) in their description, there would have been the possibility of error as we do not know the orientation of the vector.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!