Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ///////////////////////ATRISINAJUMA FUNKCIJA//////////////////////////
- function x = funcx(x,y)
- x= 0.5*x*y-0.8*y;
- endfunction
- function y = funcy(x,y)
- y=y-0.4*x*y;
- endfunction
- /////////////////////Eilera Algoritms////////////////////////////////////
- function [t,x,y] = euler_method_system(fx,fy,t0,x0,y0,h,b)
- n=(b-t0)/h;
- x(1)=x0;
- y(1)=y0;
- t(1)=t0;
- for i = 2:n
- t(i)= t(i-1)+h;
- x(i) = x(i-1)+h*fx(x(i-1), y(i-1));
- y(i) = y(i-1)+h*fy(x(i-1), y(i-1));
- end
- endfunction
- //////////////////////////ATRISINAJUMS/////////////////////////////////
- x0=3;y0=1;t0 = 0; h1=0.1;b=5;
- [t1,x2,y2]=euler_method_system(funcx,funcy,t0,x0,y0,h1,b);
- function dy = fun(x,y)
- dy(1)=0.5*y(1)*y(2)-0.8*y(2);
- dy(2)=y(2)-0.4*y(1)*y(2);
- //x - y(1)
- //y=y(2)
- //x'=dy(1)
- //y'=dy(2)
- endfunction
- yr0=[x0;y0]
- yx=ode(yr0,t0,t1,fun);
- plot(t1,yx(1,:),'b');
- plot(t1,yx(2,:),'g');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement