Find the root of equation: x-cosx = 0. using iterative method. Take initial value X = 1 [Calculation up to 4 decimal places]
Program:
<?php
$c = 2; // Counter Start Value Assign Here.
$x = "";
$x2 = 1; // Initial value Assign Here.
echo "X 1 = 1 <br />"; // Assign X1 Value Here.
for ($i = 2; $i <= $c; $i = $i+1) {
$x=$x2;
// Simplify Equation Here.
$x2 = number_format((cos($x)),"4",".","");
$c++; // Increment Counter Value.
echo "X $i = " .$x2 . '<br />';
if ($x === $x2) {
echo "<h3 style = 'color:green'> Hello same value $x2 is found. </h3>";
$c = $i-1;
}
}
?>
Program:
<?php
$c = 2; // Counter Start Value Assign Here.
$x = "";
$x2 = 1; // Initial value Assign Here.
echo "X 1 = 1 <br />"; // Assign X1 Value Here.
for ($i = 2; $i <= $c; $i = $i+1) {
$x=$x2;
// Simplify Equation Here.
$x2 = number_format((cos($x)),"4",".","");
$c++; // Increment Counter Value.
echo "X $i = " .$x2 . '<br />';
if ($x === $x2) {
echo "<h3 style = 'color:green'> Hello same value $x2 is found. </h3>";
$c = $i-1;
}
}
?>