Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clc;
- clear all;
- close all;
- yk=1; % krok początkowy
- xk=0; %krok początkowy
- eps=0.01; %dokładność
- h=0.05; %krok
- f = @(x,y) 2*y*x; %podana funkcja
- k=0;
- while(k<4) %algorytm Rungego-Kutty
- s1=h*f(xk,yk);
- s2=h*f(xk+(1/2*h),yk+(1/2*s1));
- s3=h*f(xk+(1/2*h),yk+(1/2*s2));
- s4=h*f(xk+h,yk+s3);
- T=abs((s2-s3)/(s1-s2));
- wyn(k+1,:)=[k, xk, yk, s1, s2 ,s3, s4, T, h];
- if(T<=0.05)
- wyn(k+2,3)=wyn(k+1,3)+(1/6*s1)+(1/3*s2)+(1/3*s3)+(1/6*s4);
- else
- h=h/2;
- continue
- end
- yk=wyn(k+2,3);
- k=k+1;
- xk=xk+h;
- end
- k=4;
- xk=0.2;
- while(xk<=1+h) %algorytm Adamsa
- k=k+1;
- wyn(k,1)=k-1;
- wyn(k,2)=xk;
- wyn(k,3)=wyn(k-1,3)+(h/24)*((55*f(wyn(k-1,2),wyn(k-1,3)))-(59*f(wyn(k-2,2),wyn(k-2,3)))+(37*f(wyn(k-3,2),wyn(k-3,3)))-(9*f(wyn(k-4,2),wyn(k-4,3))));
- xk=xk+h;
- end
- fprintf('Kolejno: k, x, y, s1...s4, T, h');
- wyn
Advertisement
Add Comment
Please, Sign In to add comment