fork download
  1. # your code goes%writing the function
  2.  
  3. f=@(x,y) 2*x;
  4.  
  5. %writing the step size which means hasOwnProperty
  6.  
  7. %number of steps
  8.  
  9. h=0.4;
  10.  
  11. n=(2-0)/h;
  12.  
  13. %initial value
  14.  
  15. x(1)= 0;
  16. y(1)= 1;
  17. %loop
  18. for i = 1:n
  19. x(i+1) = x(i) + h; %step size baray 0.4-0.8
  20. y(i+1) = y(i) + h *f(x(i), y(i)); %euler formula
  21.  
  22. end
  23.  
  24. %to show the output
  25.  
  26. disp([x' y'])
  27.  
  28.  
  29.  
Success #stdin #stdout 0.15s 46520KB
stdin
Standard input is empty
stdout
   0.00000   1.00000
   0.40000   1.00000
   0.80000   1.32000
   1.20000   1.96000
   1.60000   2.92000
   2.00000   4.20000