Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- clc;
- clear all;
- close all;
- fxy='-1.2*y+7*exp(-0.3*x)';
- dfxy='-1.2';
- h=0.5;
- %h=0.1;
- %h=0.01;
- a=0;
- b=2.5;
- n=(b-a)/h;
- Y0=3;
- X0=a;
- Y(1)=Y0;
- X(1)=X0;
- % Euler Simples
- for i=1:n
- disp('----------------------------------------------------------------')
- disp(['Iteração' num2str(i)])
- y=Y(i);
- disp([[['y' num2str(i)] '='] num2str(y)])
- x=X(i);
- disp([[['x' num2str(i)] '='] num2str(x)])
- disp(['f(x,y) -> ' fxy])
- Fxy(i)=eval(fxy);
- disp([[[[['f(x' num2str(i)] ',y'] num2str(i)] ')='] num2str(Fxy(i))])
- X(i+1)=x+h;
- Y(i+1)=y+h*Fxy(i);
- disp([[[['x' num2str(i+1)] ' = '] ['x' num2str(i)]] ' + h'])
- disp([[['x' num2str(i+1)] '='] num2str(X(i+1))])
- disp([[[['y' num2str(i+1)] ' = '] ['y' num2str(i)]] [[' + ' [[[['f(x' num2str(i)] ',y'] num2str(i)] ')'] ] '*h']])
- disp([[['y' num2str(i+1)] '='] num2str(Y(i+1))])
- end
- XX=a:0.01:b;
- YY=(70/9)*exp(-0.3*XX)-(43/9)*exp(-1.2*XX);
- plot(X,Y,'r*',XX,YY)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement