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
ppmtosixel(1)						      General Commands Manual						     ppmtosixel(1)

NAME
ppmtosixel - convert a portable pixmap into DEC sixel format SYNOPSIS
ppmtosixel [-raw] [-margin] [ppmfile] DESCRIPTION
Reads a portable pixmap as input. Produces sixel commands (SIX) as output. The output is formatted for color printing, e.g. for a DEC LJ250 color inkjet printer. If RGB values from the PPM file do not have maxval=100, the RGB values are rescaled. A printer control header and a color assignment table begin the SIX file. Image data is written in a compressed format by default. A printer control footer ends the image file. OPTIONS
-raw If specified, each pixel will be explicitly described in the image file. If -raw is not specified, output will default to com- pressed format in which identical adjacent pixels are replaced by "repeat pixel" commands. A raw file is often an order of magni- tude larger than a compressed file and prints much slower. -margin If -margin is not specified, the image will be start at the left margin (of the window, paper, or whatever). If -margin is speci- fied, a 1.5 inch left margin will offset the image. PRINTING
Generally, sixel files must reach the printer unfiltered. Use the lpr -x option or cat filename > /dev/tty0?. BUGS
Upon rescaling, truncation of the least significant bits of RGB values may result in poor color conversion. If the original PPM maxval was greater than 100, rescaling also reduces the image depth. While the actual RGB values from the ppm file are more or less retained, the color palette of the LJ250 may not match the colors on your screen. This seems to be a printer limitation. SEE ALSO
ppm(5) AUTHOR
Copyright (C) 1991 by Rick Vinci. 26 April 1991 ppmtosixel(1)
All times are GMT -4. The time now is 08:00 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy