RK23 with given coefficients
Afficher commentaires plus anciens
I have an IVP;
;
; 
and 
I want to use RK23, but it seems my 'C' coefficient is unused as the RHS of my equation, f(u), only has one argument i.e u.

function udot = eqns(u)
udot=(-sin(2*pi*u));
end
I know it has to be used somewhere but I can't figure this out. Below is my code so far
function [u, h] = func_particle_rk3_generic(u_0, tmax, N)
a = zeros(3,3);b = zeros(1,3);c = zeros(3,1);
h = tmax/N;
u = u_0;
t = [0,tmax];
for i = 1:N
t(i+1) = i*h;
k(:,1)=eqns(u);
k(:,2)=eqns(u+h*(a(2,1)*k(:,1)));
k(:,3)=eqns(u+h*(a(3,1)*k(:,1)+a(3,2)*k(:,2)));
u = u + h*(b(1)*k(:,1) + b(2)*k(:,2) + b(3)*k(:,3));
end
It doesn't gives me an error, but it doesn't also gives me the accuracy I want to get when compared to the uExact
3 commentaires
a = zeros(3,3);b = zeros(1,3);c = zeros(3,1);
??? That's not RK23.
If you are only interested in u at t=tend, your code should work. But usually, one wants to see the time development of u:
u(1) = u0;
...
u(i+1) = u(i) + h*(b(1)*k(:,1) + b(2)*k(:,2) + b(3)*k(:,3));
lord_eul3r
le 18 Déc 2022
lord_eul3r
le 18 Déc 2022
Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Symbolic Math Toolbox dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
