Advertisement
sconetto

MNE - EDO Método de Euler Simples

Jun 15th, 2016
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 0.95 KB | None | 0 0
  1. clc;
  2. clear all;
  3. close all;
  4.  
  5. fxy='-1.2*y+7*exp(-0.3*x)';
  6. dfxy='-1.2';
  7. h=0.5;
  8. %h=0.1;
  9. %h=0.01;
  10. a=0;
  11. b=2.5;
  12. n=(b-a)/h;
  13. Y0=3;
  14. X0=a;
  15. Y(1)=Y0;
  16. X(1)=X0;
  17.  
  18. % Euler Simples
  19. for i=1:n
  20.     disp('----------------------------------------------------------------')
  21.     disp(['Iteração' num2str(i)])
  22.     y=Y(i);
  23.     disp([[['y' num2str(i)] '='] num2str(y)])
  24.     x=X(i);
  25.     disp([[['x' num2str(i)] '='] num2str(x)])
  26.     disp(['f(x,y) -> ' fxy])
  27.     Fxy(i)=eval(fxy);
  28.     disp([[[[['f(x' num2str(i)] ',y'] num2str(i)] ')='] num2str(Fxy(i))])
  29.     X(i+1)=x+h;
  30.     Y(i+1)=y+h*Fxy(i);
  31.     disp([[[['x' num2str(i+1)] ' = '] ['x' num2str(i)]] ' + h'])
  32.     disp([[['x' num2str(i+1)] '='] num2str(X(i+1))])
  33.     disp([[[['y' num2str(i+1)] ' = '] ['y' num2str(i)]] [[' + ' [[[['f(x' num2str(i)] ',y'] num2str(i)] ')'] ] '*h']])
  34.     disp([[['y' num2str(i+1)] '='] num2str(Y(i+1))])
  35. end
  36.  
  37. XX=a:0.01:b;
  38. YY=(70/9)*exp(-0.3*XX)-(43/9)*exp(-1.2*XX);
  39. plot(X,Y,'r*',XX,YY)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement