banner



How To Find The Roots Of A Cubic Function

Observe cubic root of a number in C++


Hither we volition see how to get the cubic root of a number. Suppose a number is say 27, then the cubic root of this number is 3. To solve this problem, we will ascertain our own logic without using some library functions. We will use the binary search approach. We have to follow these steps to solve this trouble.

Suppose we have threshold value like threshold = 0.000001

  • Start the left value as 0, and right value as number

  • calculate mid := (left + correct)/ii

  • if the absolute value of (number – mid3) is less than threshold, and so return mid as reply

  • if mid3 is greater than number, then set correct := mid

  • if mid3 is less than number, then set left := mid

Example

#include<iostream> #include<cmath> using namespace std;    double cubeRoot(int num) {    double threshold = 0.000001;    double left = 0, right = num;    double mid;    while(left <= right){       mid = (left + right)/ii;       if(abs(num - (mid*mid*mid)) < threshold)          return mid;       if((mid*mid*mid) > num)          right = mid;       if((mid*mid*mid) < num)          left = mid;    } } int main() {    int n = three;    cout << "cube root of 3 is: " << cubeRoot(n); }

Output

cube root of 3 is: 1.44225

raja

Published on 01-Nov-2019 07:07:38

  • Related Questions & Answers
  • 5th root of a number in C++
  • N-th root of a number in C++
  • 8086 program to find the square root of a perfect square root number
  • 8085 program to find square root of a number
  • 8086 program to find Square Root of a number
  • How to find the cube root of a number in JavaScript?
  • Java program to discover the foursquare root of a given number
  • Java program to find the cube root of a given number
  • Observe square root of number upto given precision using binary search in C++
  • Primitive root of a prime number due north modulo n in C++
  • Find Nth positive number whose digital root is X in C++
  • Number of elements smaller than root using preorder traversal of a BST in C++
  • Usage of cubic-bezier() CSS function
  • JavaScript to Summate the nth root of a number
  • How to calculate square root of a number in Python?

Source: https://www.tutorialspoint.com/find-cubic-root-of-a-number-in-cplusplus

Posted by: kirbycathe1975.blogspot.com

0 Response to "How To Find The Roots Of A Cubic Function"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel