w 4 punkcie jest wzor
\(\displaystyle{ x _{k+1}=x _{k}- \frac{f(x _{k}) }{f'(x _{k})}}\)
f'(x) pochodna f(x)
Kod: Zaznacz cały
#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
float lukasz(float x)
{
float y;
y=x-exp(-x);
return y;
}
float pochodna (float x)
{
float y;
y=1+exp(-x);
return y;
}
int main(void)
{
float d;
int b;
float x,a;
cout<<"Podaj przedzialy w ktorych chcesz szukac miejsc zerowych: ";
cin>>a;
cin>>b;
d=1/1000000;
cout<<setw(10)<<fixed<<"y";
cout<<setw(10)<<fixed<<"x"<<endl;
if(lukasz(a)*lukasz(b)<0)
x=a;
do {
if ((fabs(lukasz(x)))>d) {
x=x-lukasz(x)/(pochodna(x));
cout<<setw(10)<<lukasz(a);
cout<<setw(10)<<a<<endl;
}}
while(fabs(lukasz(x))<d);
system ("pause");
return 0;
}