Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clear all;
- close all;
- clc;
- format long;
- %%%%% METODA MONTE-CARLO
- f1 =@(x) x.^7 - 2.*x.^4 + 2.*x.^2 + 1;
- a=0;
- b=1;
- N=1000;
- x = linspace (a,b,N);
- %%%%%%% METODA PODSTAWOWA
- calka_podstawowa =0;
- for(k=1:N)
- calka_podstawowa = calka_podstawowa + f1(x(k))/N;
- end
- calka_podstawowa
- %%%%%%%%% METODA ORZEŁ RESZKA
- y = f1(x);
- c=0;
- for(k=1:N)
- punkt = rand(1,2);
- punkt(2) = 2*punkt(2);
- if (punkt(2) <= f1(punkt))
- plot(x,y,punkt(1),punkt(2),'or')
- hold on;
- else
- plot(x,y,punkt(1),punkt(2),'og')
- hold on;
- end
- if (punkt(2) <= f1(punkt))
- c=c+1;
- end
- end
- calka_orzel_reszka = (c/N)*2
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement