Sponsored Content
Top Forums Programming Need some advices how to increse accuracy of the algorithm Post 302512505 by solaris_user on Sunday 10th of April 2011 04:51:06 PM
Old 04-10-2011
Need some advices how to increse accuracy of the algorithm

Hi guys Smilie

Can you raccomand some what I can do to increse accuracy of the Newton-Raphons method. It's not very accurate.

Code:
// Implementation of Newton - Raphson method for
// determination square root od positive number 
// Date: 10. april 2011
// Author: Solaris_user 
// Solution for programming exercise 13

#include <stdio.h>

int main(void) {
    
    double tolerance, input, y, x = 1.0;
    
    // Ask user to enter some number to find square root 
    // if user enters negative number then re-ask for new input
    // input must be greater then numbers zero and one. 
    // also user must enter some tolerance which will controll loop 
    // test condition    

    printf("Newton - Raphson square root algorithm\n");
    
    do {
        printf("Enter some number to find squre root: ");
        scanf("%lf", &input);
        if (input <= 1) {
            printf("Can't find square root for input number\n");
            }
        } while (input < 1);
    
    do {
        printf("Enter desired tolerance ( < 0.01): ");
        scanf("%lf", &tolerance);
        if (tolerance >= 0.01) {
            printf("Too small tolerance\n");
            }
        } while (tolerance >= 0.01);
    
    // Newton - Raphson method: 
    // start with x = 1.0. Then set y = (x + input/2) / 2 . If x and y are not 
    // close enough then set x = y, stop when difference is small enough 
    // to be negligible. 
    
    do {
        y = (x + (input / 2) ) / 2;
        if (x > y ) {
            x = y;
            }
        } while ( (x - y) > tolerance);
    
    printf("Square root is %.7lf\n", y);    
    return 0;
}

This is my output

Code:
Solaris:~/Desktop> ./a.out
Newton - Raphson square root algorithm
Enter some number to find squre root: 9
Enter desired tolerance ( < 0.01): 0.00000001
Square root is 2.7500000

 

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Error: when i try to Increse the size of LV

I have AIX 5.1, and one of my LV is 100% used... and i have PP's available to incresed the size... and When i try Increase the Size of a Logical Volume... the SMITTY CONSOLE display an error... ERROR MESSAGE Press Enter or Cancel to return to the application. 1820-037 An internal... (0 Replies)
Discussion started by: mgonzal
0 Replies

2. HP-UX

vmstat, comments and advices needed

Hi all.. I need some comments or advices about my HP-UX 11.11 performance. It runs Oracle, some apps and weblogic. For several times in a day, it's performance drops poorly (approx for minutes until an hour). I tried to find articles about unix, oracle and weblogic tuning, which leads me... (13 Replies)
Discussion started by: galapagos
13 Replies

3. Shell Programming and Scripting

Need advices on scripting for remote servers

Hi guys, I need some advice and recommendations for a work project I am doing. Let me state that security is not a concern as this is a closed network and the data is not sensitive. Here's what I would like to do and how I was planning to accomplish it: I have an application on my remote... (1 Reply)
Discussion started by: blueicedrop2000
1 Replies

4. Filesystems, Disks and Memory

Linux Storage system: looking for advices

Gidday! I'd like to setup a storage server for a friend of mine (he is a hobby photographer, and he produces about 100Gb pictures monthly). My friend has the following PC-Server-like system: AMD Athlon Dual Core Processor 4850e. ASUS M3N78-EMH HDMI motherboard with 6 SATA connectors. 3Gb... (7 Replies)
Discussion started by: Loic Domaigne
7 Replies

5. Shell Programming and Scripting

Getting column with pinpoint accuracy

Hello scripters, what is the best way to parse 6.2mb in this line? i know how to get that column, but i wanna see if there is a better way to do it. Jun 22 2011 10:45:26 PROCESS NAME:httpd PID: 19910 CPU UTIL: 0.0% MEM UTIL: 6.2mb THREAD COUNT: 1 (2 Replies)
Discussion started by: ryandegreat25
2 Replies

6. UNIX for Dummies Questions & Answers

accuracy of output - decimal points

Is there a way when using awk to specify the number of decimal points needed for the output? (2 Replies)
Discussion started by: cosmologist
2 Replies

7. IP Networking

how to increse server lan speed in hp-ux

Hi, I've a problem in hp-ux server, i.e.how to increase Ethernet speed. i dont've time to trials on production server please help me (1 Reply)
Discussion started by: karlapudi.ramu
1 Replies

8. Homework & Coursework Questions

Want to learn Shell well.. Advices

Hi everyone.. Thanks a lot for reading this post. I am trying to learn shell and Unix well. I am taking course at UNT school, unfortunately, the professor doesn't explain well. I am trying to take an advantage of this course and learn as much as I could. I learn by myself.. read the book... (1 Reply)
Discussion started by: smasm9
1 Replies

9. Fedora

Accuracy of jobs scheduled in cron

Hello, I have several cron jobs scheduled but looking at the results of running I see in some cases it takes more than 2 seconds, is there any way to adjust the accuracy of execution of cron? Is there any other tool or way to fix the problem? (10 Replies)
Discussion started by: faka
10 Replies
PAPS(1) 						      General Commands Manual							   PAPS(1)

NAME
paps - UTF-8 to PostScript converter using Pango SYNOPSIS
paps [options] files... DESCRIPTION
paps reads a UTF-8 encoded file and generates a PostScript language rendering of the file. The rendering is done by creating outline curves through the pango ft2 backend. OPTIONS
These programs follow the usual GNU command line syntax, with long options starting with two dashes (`-'). A summary of options is included below. --landscape Landscape output. Default is portrait. --columns=cl Number of columns output. Default is 1. --font=desc Set the font description. Default is Monospace 12. --rtl Do rtl layout. --paper ps Choose paper size. Known paper sizes are legal, letter, a4. Default is A4. --bottom-margin=bm Set bottom margin in postscript points (1/72 inch). Default is 36. --top-margin=tm Set top margin. Default is 36. --left-margin=lm Set left margin. Default is 36. --right-margin=rm Set right margin. Default is 36. --help Show summary of options. --header Draw page header for each page. --markup Interpret the text as pango markup. --encoding=ENCODING Assume the documentation encoding is ENCODING. --lpi Set the lines per inch. This determines the line spacing. --cpi Set the characters per inch. This is an alternative method of specifying the font size. --stretch-chars Indicates that characters should be stretched in the y-direction to fill up their vertical space. This is similar to the texttops behaviour. AUTHOR
paps was written by Dov Grobgeld <dov.grobgeld@gmail.com>. This manual page was written by Lior Kaplan <kaplan@debian.org>, for the Debian project (but may be used by others). April 17, 2006 PAPS(1)
All times are GMT -4. The time now is 12:17 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy