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 次查看(过去 30 天)
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 个评论
Walter Roberson
Walter Roberson 2018-11-6
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.

请先登录,再进行评论。

回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Solver Outputs and Iterative Display 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by