how to write a code for a variant of Newton's method in calculating square root of a matrix?

Hello there, I have a question regarding a variant of Newton's method in calculating square root of a matrix. here is how the method works:
X_0=A+I,
X_{k+1}=(1/2)*(x_{k}+(x_{k}^(-1)*(A+(I/(k+1)))))
and here is the code I wrote:
A = [1 5;2 3];
I=eye(2);
for k = 0:1:10;
x0= A+I;
x1=(1/2)*(x0+(x0^(-1)*(A+(I/(k+1)))))
end
the problem is my indexing, I do not know how to write the code in a way that the calculation will continue with each time substituting the new X_{k} in the pervious formula.
Thank you for your time and attention,
Ha

 Accepted Answer

A = [1 5;2 3];
I=eye(2);
x0= A+I;
for k = 0:10
x1=(1/2)*(x0+(inv(x0)*(A+(I/(k+1)))));
x0 = x1;
end
Best wishes
Torsten.

3 Comments

Thank you, you were a big help, at first I ran into some problems but then I modified your X1 line to the following, and it worked perfectly:
x1=(1/2)*(x0+((inv(x0))*(A+(I/(k+1)))));
so thank you so much!!
Maybe I'm blind, but what's the difference between the two lines ?
Best wishes
Torsten.
Of course you're not, it's just that inv(x0) being in an parenthesis, (inv(x0))!
i might be wrong, but matlab seemed to recognize it easier, anyway thanks so much for your huge help!!

Sign in to comment.

More Answers (0)

Categories

Find more on Debugging and Improving Code 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!