Skip to content
Back to formatted view

Raw Message

Message-ID: <BN6PR2201MB1553ECA5C8D169FD479C598ACF439@BN6PR2201MB1553.namprd22.prod.outlook.com>
Date: 2022-09-09T12:39:48Z
From: Ebert,Timothy Aaron
Subject: Help with a simple subroutine
In-Reply-To: <20220909110311.396a3cd1@parabola>

If t = 1/sqrt(v[2,2]) and there is no code to change the value of v[2,2] and no code to change to a different cell why would you get two different values? 

One approach to debugging is to make a small example and see if the code output matches (line-by-line) the output you get from doing a manual calculation. If they do not match you at least know where to start looking for a problem. Hand calculation can use pencil and paper or Excel or other tools. It is a tedious task but very effective.

Tim

-----Original Message-----
From: R-help <r-help-bounces at r-project.org> On Behalf Of Ivan Krylov
Sent: Friday, September 9, 2022 5:03 AM
To: Steven T. Yen <styen at ntu.edu.tw>
Cc: R-help Mailing List <r-help at r-project.org>
Subject: Re: [R] Help with a simple subroutine

[External Email]

? Fri, 9 Sep 2022 16:46:00 +0800
"Steven T. Yen" <styen at ntu.edu.tw> ?????:

> I am expecting the line  t<-gamma/sgamma to produce two different 
> values. But I confirm that it is doing tt<-gamma[1]/sgamma[1]

No, it just happens that gamma[1]/sgamma[1] is the same as gamma[2]/sgamma[2], subject to rounding errors:

> +   gamma<-exp(b)
> +   vgamma<-gamma^2*v[2,2]
> +   sgamma<-sqrt(vgamma)
> +   t<-gamma/sgamma

t = gamma / sgamma = gamma / sqrt(gamma^2 * v[2,2]) =
  = gamma / (abs(gamma) * sqrt(v[2,2])) = (given gamma = exp(b) > 0)
  = 1 / sqrt(v[2,2]).

--
Best regards,
Ivan

______________________________________________
R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-help&amp;data=05%7C01%7Ctebert%40ufl.edu%7C96597c0724d947d3c1ea08da9242e073%7C0d4da0f84a314d76ace60a62331e1b84%7C0%7C0%7C637983113179778561%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=EnaoCEmoUJNXsukvk8jqZVZ1tIveOeUCIX%2Bic5tMRLM%3D&amp;reserved=0
PLEASE do read the posting guide https://nam10.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r-project.org%2Fposting-guide.html&amp;data=05%7C01%7Ctebert%40ufl.edu%7C96597c0724d947d3c1ea08da9242e073%7C0d4da0f84a314d76ace60a62331e1b84%7C0%7C0%7C637983113179778561%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&amp;sdata=18MG1xlJnQE%2Bqo54jNxYAIAGqSQC%2FFQOgTOkl7Ysvc8%3D&amp;reserved=0
and provide commented, minimal, self-contained, reproducible code.