Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function [c,yc] = bijekcja(a, b, krok)
- if (sign(f(a)) == sign(f(b)))
- error('Funkcja nie ma roznych znakow na koncach przedzialu.')
- endif
- for i=1:1:krok
- c = (a+b)/2;
- yc = f(c);
- if(f(c)==0)
- disp(['Funkcja ma miejsce zerowe dla x = ' num2str(c)])
- break;
- else
- if (f(a)*f(c)<0)
- b = c;
- else
- a = c;
- endif
- endif
- endfor
- %disp(['Dla ilości kroków = ' num2str(krok)' , ' znaleziono pierwiastek w przedziale [' num2str(c) ',' num2str(b) ']'])
- endfunction
- function y = f(x)
- y = x.^3+x.^2-3*x-3;
- endfunction
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement