C :: How To Define Epsilon In Newton Raphson Square Root Program

Mar 6, 2015

I'm working on a c program that generates approximations of square roots based on newton raphson method. I worked out the approximations with another method I learnt and I know this program does fine. But I don't get the concept of epsilon. Below is the code for the program

Code:

#include<stdio.h>
// function to compute absolute value
float absoluteValue(float x)
{
if(x < 0)
x = -x;

[code]....

The text I worked this code from uses the epsilon value arbitrarily. how is the epsilon value selected? I tried using this formula to derive the square root of 45. On paper I can go as far as 6.8 something. But once this value is reached it's still bigger than epsilon, so shouldn't the code keep running? The program generates 1.41 for 2, but since it could go further why does the while loop in squareRoot function terminate?

View 2 Replies


ADVERTISEMENT

C++ :: Newton Method Program For The Square Root Of A Number

Mar 1, 2013

I have been trying to write a Newton's Method program for the square root of a number and have been failing miserably...

#include <iostream>
#include <cmath>
using namespace std;
int main() {
double x1;
double y;
double x0;

[Code] .....

View 6 Replies View Related

C :: Program To Find The Square Root Of A Number

Dec 5, 2013

I am writing a program to find the square root of a number. I am using the Newton-Raphson method..Just to clarify a bit of the code.. fabs(1/(x+1)) < 0.001 is to check for relative error..

EXAMPLE: for user entry of 100 if the iteration process ends in 10.055 the answer will return as 10 which is correct. But it isn't doing that.

It compiles I then proceed to run it..prompts me "Enter a number to find the square root of: I type 100 then hit enter...

"The square root of 100 is -1077834936"

My first time writing a program from complete scratch.

And I know there is a sqrt() function...just wanted to write my own.

Code:

#include <stdio.h>
#include <math.h>
double mysqrt(double a);
int main()
{
double a, result;
printf("Enter a number to find the square root of: ");

[Code]...

View 1 Replies View Related

C++ :: Square Root Of Number

Dec 9, 2013

i have written a function that gives me the square root of a number. Yes i know there is already a function in <cmath> that gives square roots but i thought it would be pretty challenging (and therefore fun) to try writing one on my own. I wrote my code while i was in school, listening to my Irish teacher ramble on and on about useless shit, so it's probably not the best possible way of finding the square root of a number.

double msqrt(double x) {
double adder=1;
double y = x;
for(int a=0; ; a++) {
if(y*y > x) y = y/2;
if(y*y <= x) break;

[code]....

View 6 Replies View Related

C :: Prototype Function Square Root Velocity

Mar 30, 2013

I am trying to computed the time it takes for a projectile to hit the ground. The problem is that i need to square the input of velocity before i do the calculation. the question I have is that if it's possible to have multiple arguments inside the brackets after main.

#include <stdio.h>
#include <math.h>
double distance (double a, double v, double g);
int square(int y);
double height(double v, double a, double g);
double time (double v, double a, double g);
double sqrt(double num);

[Code] ....

View 2 Replies View Related

C :: Function Macro For Finding Square Root Of A Number

Jul 13, 2014

How to write a function macro in C for finding the sqrt of a number?

View 2 Replies View Related

C++ :: How To Find The Square Root For Numerator And Denominator Separately

Apr 1, 2014

I having trouble with the rational class

here is my assignment:

Add a square root function to the rational class. Have your program print the square root of any rational number. I want to find the square root for numerator and denominator separatetly. divide the answer to get decimals and convert the decimal to fractions. i got till geting the decimal but i want to convert it back to a simplified fraction

// finding greatest common factor
int gcd(int a, int b)
{
if (b == 0)
return a;
else
return gcd(b, a % b);
}

[Code]...

View 2 Replies View Related

C/C++ :: Check Rational Or Irrational Numbers After Taking Square Root?

Aug 4, 2014

I tried to check the rational or irrational numbers after we take the square root. i dont get the formula. for eg. squareroot of 64 is 8 and it is rational. square root of 2 is irrational. how to check it in c++..

View 10 Replies View Related

C++ :: User Input Two Numbers - Calculate Square Root Then Roots Are Added Up To Return Sum

Aug 23, 2014

I have tried writing a code which takes two numbers from the user and calculates their square root then the roots are added up to return the sum. The program is coming out with loads of errors.

#include<iostream>
#include<cmath>
float main(){
using namespace std;
float m1,m2,m3,m4,m5;

[Code] ....

View 4 Replies View Related

C/C++ :: Displaying Filled Square Next To Hollow Square?

Feb 28, 2015

I am able to display a filled and hollow square by themselves, but I can't seem to be able to get them side by side.

So this is my code so far:

[/
#include <iostream>
using namespace std;
int main()

[Code]....

I can get the hollow square to show up, but the first square just shows up as a single line instead of a square. It seems that it ignores the first if statement in the second loop. I've tried not using an if statement in the second loop but it didn't seem to work either.

View 4 Replies View Related

C++ :: How To Square And Cube Number In Program

Feb 18, 2014

#include <iostream>
#include <conio.h>
#include <iostream>

[Code].....

I can't find a way to square and cube the number I want, which the number will show in the notepad. Is there a way to cube and square a number in my program??

View 5 Replies View Related

C/C++ :: Make Program To Square Numbers From 1 To 20

Oct 21, 2012

I want to make program to square the numbers from 1 to 20. i have written this program, it's running but not giving the required answer.i think it is giving a garbage value...

void main(void)
{int a;
  int  b;
b=a*a;
for (a=1; a<21; a++)
{printf("%d",b);
printf("the square is%d=b");
}
getche();}

View 2 Replies View Related

C++ :: Program To Find Transpose Of Given Square Matrix

Mar 24, 2013

I want to find transpos of square matrix.but my program does not run complete.

Code:
#include<iostream>
using namespace std;
const int size=3;
void read(int a[size][size])

[Code] .....

View 2 Replies View Related

C++ :: Program That Will Ask User To Enter Area Of Square?

Feb 11, 2013

B. Circle in a Square Write a C++ program that will ask the user to enter the area of a square. Then the program will display the biggest area of a circle that will fit in a given square. Using math.h library is not allowed.

View 1 Replies View Related

C++ :: Write Program To Find Area Of A Square

Feb 1, 2013

write a C++ program to find the area of a square, input the length of the side, and output your answer to the screen.

View 3 Replies View Related

C++ :: Draw A Square Within A Square Pattern

Oct 25, 2013

I know how to draw a square hollow or filled but i need to draw an alternating pattern ....

ex
iPatternHeight = 1
X

iPatternHeight = 3
OOO
OXO
OOO

[Code] .....

View 6 Replies View Related

C++ :: How To Define DWORD As Still 32-bit When Compiling Program In 64bit

Jan 7, 2014

#define DWORD ?

How to I write this statement?

In my program, the DWORDs are treated as unsigned long, so that They are 64-bit "DWORDs" instead of 32-bit ones...

View 5 Replies View Related

C++ :: User Defined Program - Compute Price Per Square Inch Of Cake Using Overloading

Nov 21, 2014

Create a user-defined program that will compute the price per square inch of a cake using an “overloading”. The cake could be a circle or a square type. In the main function, ask for the price of a circle cake and its diameter, while for the square cake, ask for the price, its length and width. The process must be done inside the different function of each cake. (Note: two sub function for the computation of a circle and a rectangle)

Note that when I made this program something weird happen. After inserting the name, all things follow.

<code>
#include "stdafx.h"
#include <iostream>
using namespace std;
double areaRectangle(int l, int w);
double radiusCircle(int r);

[Cpde] .....

View 4 Replies View Related

C# :: How To Draw A Square Within A Square

Oct 25, 2013

I know how to draw a square hollow or filled but I need to draw an alternating pattern

ex
iPatternHeight = 1
X

iPatternHeight = 3
OOO
OXO
OOO

[Code] ......

View 2 Replies View Related

Visual C++ :: Program That Count From 1 To 12 And Print Count And Its Square For Each Count

Dec 16, 2014

4.1 Write a program that will count from 1 to 12 and print the count, and its square, for each count.

4.2 Write a program that counts from 1 to 12 and prints the count and its inversion to 5 decimal places for each count. This will require a floating point number.

4.3 Write a program that will count from 1 to 100 and print only those values between 32 and 39, one to a line. Use the incrementing operator for this program.

View 2 Replies View Related

C++ :: Splaying Elements To The Root

Dec 13, 2014

I am having some difficulties splaying this element to the root.. Considering i have this splay tree .

0

1

2

3

4

What are the steps to get it 4 to the root?

View 1 Replies View Related

C++ :: BST - Any Way To Travel From A Leaf To The Root

Apr 30, 2014

Any way to travel from a leaf to the root. For example I search the tree to find the leaf i want and then trace/record the path back to the root.

View 2 Replies View Related

C++ :: BST Comparing Parents To The Root

Mar 18, 2014

Lets say for example I have a BST that is sorted by char names, using strcmp. IF greater than 0 go right else go left.

I.E (this is just an example, they are not inserted correctly)

cat
/
dog buffalo
/ /
fish mouse zebra snake

I wanted to make a copy of this BST IF the length of the nodes are greater than the root, how would I approach this? I kinda started on this but I'm not sure if I'm making this more difficult than it should be.

void BST::copygreater(node * root, node *& dest, int & holder) {
if(!root) {
dest = NULL;
return;
}

holder = strlen(root->name) + 1; //Don't know about this? If we do a recursive call then the value would change every call?

[Code] ......

View 2 Replies View Related

C++ :: Null Root Binary Tree

May 19, 2013

I got problem in binary tree code. below is my code. When i select pre, post or inorder, the .exe is not responding.. Since in my binary tree theres no roots yet.. who do i solve it? It need condition or what?

View 1 Replies View Related

C++ :: Parse The Root Directory Of FAT32?

Dec 27, 2013

I'm trying to parse the root directory of FAT32 in order to get a dir list in the root folder.

So I need to go over all the directory entries in the root directory and parse them.

My problem is that I don't know when to stop the iteration - How to get the size of the root directory?

I noticed that there is a byte in the boot sector - the number of the entries in the root - but in FAT32 the value is always 0, So how can i get the size of the directory?

View 1 Replies View Related

C :: Recursion For Finding Distance Between Root And Leaf?

Jun 19, 2013

I wrote the following recursion for finding the distance between a root and a leaf, but am not quite sure how to make it work.

Code:
int calc_depth(Node* tree, Node* zero) {
if (!tree)
return 0;
if (zero->right || zero->left == tree)
return 1;
return (zero->right ? calc_depth(tree, zero->right) : calc_depth(tree, zero->left));
}

View 14 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved