Randomsurpriseguy

Num2B3A3

May 5th, 2020
1,545
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function [a,b] =Aufgabe3(f,y0,t_vec)
  2.  
  3.   y_vec=t_vec;
  4.   y_vec(1)=y0;
  5.   y_vec(2)=approx(y0,y0*2+1,@(x) y0+(t_vec(2)-t_vec(1))/2*(f(t_vec(1),y0)+f(t_vec(2),x))-x);
  6.   %wird die Funktion f an approx weitergegeben, sodass in jedem Approxschritt f erne
  7.  
  8.   for i= 3:length(y_vec)
  9.      y_vec(i)=approx(y_vec(i-1),y_vec(i-2),@(x) y_vec(i-1)+(t_vec(i)-t_vec(i-1))/2*(f(t_vec(i-1),y_vec(i-1))+f(t_vec(i),x))-x);
  10.      
  11.      
  12.      
  13.   endfor  
  14.  
  15.   a=t_vec;
  16.   b=y_vec;
  17.   plot(a,b);
  18.    
  19.  
  20. endfunction
  21.  
  22.  
  23. function r=approx(in1,in2,g)
  24.   test=1
  25.   while abs(g(in2))>0.00001
  26.     in1=in2-(in2-in1)/(g(in2)-g(in1)) * g(in2);
  27.     in2=in1-(in1-in2)/(g(in1)-g(in2)) * g(in1);
  28.     test=test+1
  29.   endwhile
  30.   r=in2;
  31. endfunction
  32.  
  33. %Die Anfangswertaufgabe aus der Uebung laesst sich mit folgender Eingabe in der Console loesen:
  34. % [a,b]=Aufgabe3(@(t,y) 1-y^2+t^2,1, 0:0.1:1)
RAW Paste Data

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×