0
$\begingroup$

I have the following values for x[[i]], y[[i]] and A[[i,j]]:

x[[1]] = 4/5 x[[2]] = 31/39

y[[1]] = 2/5 y[[2]] = 145/357

A[[1,1]] = 62243/100000 A[[1,2]] = 3239/6250 A[[1,3]] = 17631/25000

I want to compute the value of an expression, specifically

A[[1, 3]] - A[[1, 1]]*x[[i]] - A[[1, 2]]*y[[i]]

So what I do is:

For[i = 1, i < 3, i++, error[[i]] = N[A[[1, 3]] - A[[1, 1]]*x[[i]] - A[[1, 2]]*y[[i]], 100]; ] error

So I get:

error[[1]] = 0 error[[2]] = -1.6871363930187...1687*10^-6.

But this is wrong since the correct result for the 1st loop is error[[1]] = -27/2500. The strange thing here is that if I compute (5*17361 - 62243 - 8*3239) / 125000 , which is practically the same operation, I get the correct result. What can I do to get the correct result? I used the N with precision of 100 digits, but obviously it is not working, FullForm neither.

$\endgroup$

1 Answer 1

1
$\begingroup$

The result from the loop is correct. You are using two different sets of numbers. Here is the loop computation without loops.

x = {4/5,31/39}
y = {2/5, 145/357}
A = {62243/100000, 3239/6250, 17631/25000}
A[[3]] - A[[1]]*x - A[[2]]*y  (* {0, -(261/154700000)} *)
$\endgroup$
2
  • $\begingroup$ Still wrong. The first part of your answer must not be equal to 0. $\endgroup$
    – Alex
    Nov 23, 2018 at 17:33
  • $\begingroup$ Clearly it must; that's the point. You must have a typo somewhere. Note that 17361*4==69444, not 62243. $\endgroup$
    – Alan
    Nov 23, 2018 at 17:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.