Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function [a,b] =Aufgabe3(f,y0,t_vec)
- y_vec=t_vec;
- y_vec(1)=y0;
- 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);
- %wird die Funktion f an approx weitergegeben, sodass in jedem Approxschritt f erne
- for i= 3:length(y_vec)
- 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);
- endfor
- a=t_vec;
- b=y_vec;
- plot(a,b);
- endfunction
- function r=approx(in1,in2,g)
- test=1
- while abs(g(in2))>0.00001
- in1=in2-(in2-in1)/(g(in2)-g(in1)) * g(in2);
- in2=in1-(in1-in2)/(g(in1)-g(in2)) * g(in1);
- test=test+1
- endwhile
- r=in2;
- endfunction
- %Die Anfangswertaufgabe aus der Uebung laesst sich mit folgender Eingabe in der Console loesen:
- % [a,b]=Aufgabe3(@(t,y) 1-y^2+t^2,1, 0:0.1:1)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement