School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become an Expert!

Join 307,003 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,960 people online right now. Registration is fast and FREE... Join Now!




Compute Square Root - using Scheme

 

Compute Square Root - using Scheme, Cannot compute square root

LionessHeadstrong

9 Mar, 2007 - 01:21 AM
Post #1

New D.I.C Head
*

Joined: 23 Jun, 2006
Posts: 2


My Contributions

Hello

I am trying to write a program in Dr Scheme (Lisp - scheme) that will compute a square root for me. This is what I have so far:

(define value (lambda (x) (- x 0.00000001) (* x x))
(if (lambda (= x value) x)))

But this doesn't work, anyone have any ideas?

Thanks for your help

Linda


User is offlineProfile CardPM
+Quote Post


Programmist

RE: Compute Square Root - Using Scheme

9 Mar, 2007 - 09:47 AM
Post #2

Slouching towards Bethlehem
Group Icon

Joined: 2 Jan, 2006
Posts: 1,407



Thanked: 28 times
Dream Kudos: 100
Expert In: Java

My Contributions
http://www.google.com/search?hl=en&q=s...G=Google+Search
User is offlineProfile CardPM
+Quote Post

numerical_jerome

RE: Compute Square Root - Using Scheme

15 Aug, 2008 - 07:14 PM
Post #3

D.I.C Head
**

Joined: 16 Sep, 2007
Posts: 164



Thanked: 10 times
My Contributions
if this was a school assignment, this might be a little far from what your professor wanted, but

[math]
sqrt(x) == x^0.5
x == e^(ln(x))
x^0.5 == e^(0.5*ln(x))
sqrt(x) == e^(0.5*ln(x))
[/math]

this is actually very fast, as your floating point unit has an optimized natural log / natural exponent

in common lisp this looks like:

CODE

(defun my_sqrt (a)
    (exp (* 0.5 (log a))))


in scheme this would be something like:

CODE

(define my_sqrt (lambda (a)
    (exp (* 0.5 (log a)))))


If your instructor complains, demonstrate the great speed at which your function evaluates, and point out how the fancier bits of the FPU can be developed from ln, e using a similar technique

User is offlineProfile CardPM
+Quote Post

NickDMax

RE: Compute Square Root - Using Scheme

15 Aug, 2008 - 07:55 PM
Post #4

Can grep dead trees!
Group Icon

Joined: 18 Feb, 2007
Posts: 5,265



Thanked: 293 times
Dream Kudos: 1175
Expert In: Java/C++

My Contributions
The posts are old but thanks for the responses. I used to try to answer scheme and lisp questions but it really hurts my head... welcome to DIC!
User is offlineProfile CardPM
+Quote Post

khoriayton

RE: Compute Square Root - Using Scheme

15 Sep, 2009 - 12:29 PM
Post #5

New D.I.C Head
*

Joined: 15 Sep, 2009
Posts: 2

how can i find the cube root of a number using scheme?
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 06:43AM

Live Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month