Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SKRYPT.M
- format long
- %Zadanie 10.47
- function y=f(x)
- y= x- 0.8 - 0.2*sin(x);
- endfunction
- function y=g(x)
- y= 1 -(cos(x)/5);
- endfunction
- a = 0;
- b = pi/2;
- %dk to dokladnosc a takze epsilon
- dk = ((10)^(-4));
- [wynik_nw,blad_teo] = oblicz_nt( @f, @g, a, b, dk );
- %Przyblizenie pierwiastka
- wynik_nw
- %blad teoretyczny
- blad_teo
- %funkjca octave
- f_solve = fsolve(@f,a)
- %funkjca octave
- f_zero = fzero(@f,a)
- OBLICZ_NT.M
- % p - pochodna | dk - dokladnosc a takze epsilon | oblicz_nt = obliczenie newtona|
- function [wynik_nw,blad_teo] = oblicz_nt( f, p, a, b, dk )
- x(1) = (a+b)/2;
- n=1;
- do
- n++;
- if ( p(x(n-1)) == 0 )
- wynik_nw = NaN;
- blad_teo = NaN;
- break;
- else
- x(n) = x(n-1) - (f(x(n-1)) / p(x(n-1)));
- wynik_nw = x(n);
- blad_teo = ( x(n-1) - x(n) )^2;
- endif
- until( ( x(n-1) - x(n) )^2 < dk)
- endfunction
- Sesja Octave
- >> format long
- >> %Zadanie 10.47
- >> function y=f(x)
- y= x- 0.8 - 0.2*sin(x);
- endfunction
- >> function y=g(x)
- y= 1 -(cos(x)/5);
- endfunction
- >> a = 0;
- >> b = pi/2;
- >> %dk to dokladnosc a takze epsilon
- >> dk = ((10)^(-4));
- >> [wynik_nw,blad_teo] = oblicz_nt( @f, @g, a, b, dk );
- >> %Przyblizenie pierwiastka
- >> wynik_nw
- wynik_nw = 0.964333889010316
- >> %blad teoretyczny
- >> blad_teo
- blad_teo = 1.417988329920676e-08
- >> %funkjca octave
- >> f_solve = fsolve(@f,a)
- f_solve = 0.964333889010601
- >> %funkjca octave
- >> f_zero = fzero(@f,a)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement