Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Integrala Richardson
- #include <iostream>
- #include <cmath>
- using namespace std;
- float f(float x)
- {
- return x*exp(x*x);
- }
- float rick (float ls, float ld, int n, int m)
- {
- float h, k, sumh, sumk, sum;
- int i;
- h=(ld-ls)/n;
- k=(ld-ls)/m;
- sumh=(f(ls)+f(ld))/2*h;
- sumk=(f(ls)+f(ld))/2*k;
- for(i=1;i<=n-1;i++) sumh+=h*f(ls+i*h);
- for(i=1;i<=m-1;i++) sumk+=k*f(ls+i*k);
- sum=sumh+(sumh-sumk)/((k/h)*(k/h)-1);
- return sum;
- }
- int main() {
- cout<<rick(2.1, 3.2, 1000, 1200);
- }
- //derivata
- #include <iostream>
- #include <cmath>
- using namespace std;
- float f (float x){return exp(x);
- }
- float d2p(float x0, float h)
- {
- return (f(x0+h/2)-f(x0-h/2))/h;
- }
- int main ()
- {
- float x0=0, h=1e-4;
- cout<<d2p(x0, h);
- }
- //Integrala Simpson
- #include <iostream>
- #include <cmath>
- using namespace std;
- float f(float x)
- {
- return x*exp(x*x);
- }
- float simpson (float ls, float ld, int n)
- {
- float h, sum;
- int i;
- h=(ld-ls)/n;
- sum=h*((f(ls)+f(ld))/3);
- for(i=1;i<=n-1;i++)
- {
- if(i%2==0)sum+=2*h*f(ls+i*h)/3;
- else sum+=4*h*f(ls+i*h)/3;
- }
- return sum;
- }
- int main() {
- cout<<simpson(2.1, 3.2, 1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement