Clear Filters
Clear Filters

Solve a system of three coupled first-order differential equations

15 views (last 30 days)
Hello eveyone,
I'm trying to solve the system of coupled first-order differential equations that appears in the PDF that I attach to this post. To do this, I have preliminarily created the following scripts:
function dxdt=myode(t,x,alpha,h,a,lambda)
clear all;
close all force;
%% First of all, let's introduce the related parameters
lambda=[1 10 100 1000 10000];
for i=1:length(lambda)
lambda_name={'1' '10' '100' '1000' '10000'};
field_name={'alpha_lambda_4' 'alpha_lambda_2' 'alpha_lambda' '3_alpha_lambda_2'};
%% Now, let's introduce the related time array
%% Now, let's introduce the initial conditions
%% Now, let's solve the coupled first-order differential equations
for i=1:length(lambda)
for j=1:length(field(:,i))
fnm=sprintf('C:\\Users\\890384\\Documents\\MEGA\\PhD\\Papers\\Micromagnetic Cell Size\\Numerical Calculations Thiaville Approach\\Thiaville_Numerical_lambda=%s_field=%s.txt',lambda_name{i},field_name{j});
dlmwrite(fnm,[time' sol],'delimiter',' ')
However, I don't know if it makes sense how I have written my system of differential equations in the function domain. There, I am not specifying, for example, that dxdt(1) is the first derivative with respect to time t of x(1), and the same about dxdt(2), x(2), dxdt(3), and x(3). To write the first two differential equations dxdt(1) and dxdt(2) I have decoupled the first two equations that appear in the PDF. The program works and yields results. But there are some cases of the ones contemplated in my script that output normal numerical results first, and then NaN thereafter.
Could you give me some feedback on this? If it wasn't right, how could you reorient it?

Accepted Answer

Alan Stevens
Alan Stevens on 12 Nov 2020
According to the pdf equations, instead of
you should have
Also, I suggest you use ode15s rather than ode45.
Richard Wood
Richard Wood on 13 Nov 2020
Hi Alan, thank you for your comments. You are right, I have corrected the dxdt(3) equation, thanks for noticing. On the other hand, if you allow me, I have some questions related to your answer. Why do you advise me to use ode15s instead of ode45 in this case? And on the other hand, it continues to surprise me that my differential equations are well expressed in the function environment without specifying that dxdt(1) is the first derivative in time of x(1) and so on, is my approach equally good?
Alan Stevens
Alan Stevens on 13 Nov 2020
I suggested ode15s because ode45 seemed very much slower for the higher values of lambda.
Also, I think you overdo the time specification. Why do you need an output of 10000 timesteps?
Other than that, your code seems to work (though I didn't test the two lines that print the results).

Sign in to comment.

More Answers (0)


Find more on Programming in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!