Problem with Runge-Kutta script file

Click For Summary

Discussion Overview

The discussion revolves around troubleshooting a MATLAB script that implements the Runge-Kutta method for solving ordinary differential equations (ODEs), specifically applied to the Lorenz system. Participants are examining error messages encountered while attempting to run the script files and are exploring potential solutions.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Homework-related

Main Points Raised

  • One participant describes the structure of their MATLAB scripts for the Lorenz system and the Runge-Kutta method, including the functions defined within them.
  • Another participant suggests that the error may be due to a case sensitivity issue, proposing to use "Lornz" instead of "lornz" and to initialize the variable t before calling the function.
  • A participant expresses frustration over the ongoing issue and mentions difficulties with using Octave on an older Windows system.
  • Another participant shares their experience with running a different script in Octave, indicating that they had to ensure the script was properly loaded and the path was set correctly.
  • One participant confirms that the script worked on MATLAB online but encountered issues with Octave, suggesting a possible compatibility problem.

Areas of Agreement / Disagreement

Participants have not reached a consensus on the cause of the error or the best solution. Multiple competing views and suggestions remain, with some participants proposing different approaches to troubleshoot the issue.

Contextual Notes

There are indications of potential issues related to case sensitivity in function names and the environment setup for running the scripts. Participants also mention differences in behavior between MATLAB and Octave, which may affect the execution of the scripts.

hagopbul
Messages
397
Reaction score
45
TL;DR
trying to run a multiple dependent script files at the same time but it is not working on matlab
Hello :

trying to run mutiple script files on matlab (matlab basic online) but it is giving an error message the files are about runge - kutta method and applying them on a ODEs

the 1 script file Lornz :
function dy = Lornz(t,y,sigma,beta,rho)
% y is the 3 dimensional state vector

% y(1) =x , y(2) = y , y(3) = z
dy = [
sigma*(y(2)-y(1));
y(1)*(rho-y(3))-y(2);
y(1)*y(2) - beta*y(3);
];
the second file rk4singlestep
% rang kuta function to solve the lorenz example or other function

function yout = rk4singlestep(fun,dt,tk,yk)
% fun is a function i should load into the memory from file or command
f1 = fun(tk,yk);
f2 = fun(tk+dt/2,yk+(dt/2)*f1);
f3 = fun(tk+dt/2, yk+(dt/2)*f2);
f4 = fun(tk+dt, yk + (dt)*f3);

yout = yk + (dt/6)*(f1+2*f2+2*f3+f4);

the 3ed sript file :
clear all ,close all , clc


% inputing the lorenz example parameters

sigma = 10;
beta = 8/3;
rho = 28;

% the initial condition of the lorenz function
y0 = [-8;8;27];

% computeing the trajectory
dt = 0.01;
tspan = 0:dt:4;
Y(:,1) = y0;
yk = y0;
for i=1:length(tspan)
time = i*dt;
ykplus1 = rk4singlestep(@(t,y)lornz(t,y,sigma,beta,rho),dt,time,yk);
Y = [Y ykplus1];
yk = ykplus1;
end
plot3(Y(1,:),Y(2,:),Y(3,:),'b')

the idea is that the 3ed script file load or call the function in the 1st and 2nd files

the error message
Unrecognized function or variable 'lornz'.Error in simulatelorenz>@(t,y)lornz(t,y,sigma,beta,rho) (line 20)
ykplus1 = rk4singlestep(@(t,y)lornz(t,y,sigma,beta,rho),dt,time,yk); ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Error in rk4singlestep (line 5)
f1 = fun(tk,yk);^^^^^^^^^^^^^^^^
Error in simulatelorenz (line 20)
ykplus1 = rk4singlestep(@(t,y)lornz(t,y,sigma,beta,rho),dt,time,yk); ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

the idea of this code to load the functions from other files but it is not working at all , tried to change few lines it didnt work out i cant figure out what is wrong with this code

Best Regards
H
 
Physics news on Phys.org
Hi,

Could it be as simple as using Lornz instead of lornz ?

( and putting t = 0 ; before the call to rk4singlestep )

1737208240032.png


[edit] Disclaimer: I don't have MatLab, used Octave instead.

Put all in one .m file :
(then t=0; wasn't even necessary)

##\ ##
 

Attachments

Last edited:
ahaaaaaaaaaaaaaa
days and i am looking at it say why it is not working !!!!!

i downloaded octave but using old windows so it is saying entry point not found
 
1737284425651.png


I don't know what to say. Not an expert: all trial and error experience :frown:

I have W10, double-click RK_ODE.m and do

>> RK_ODE

at the command prompt; that does the trick for me.

Do you have any .m file that runs at all ?

Can you post the complete error situation ?

[edit]If I first start up the Octave environment from the taskbar, I get
Code:
>> RK_ODE
error: 'RK_ODE' undefined near line 1, column 1
>>

then bring RK_ODE.m to the editor, click Run (green arrow, F5) and add the path, it also works fine.


##\ ##
 
it worked on matlab online ( basic) ( matlab basic is the free edition of matlab) but for octave i downloaded it and didnt work (the octave didnt run)
 

Similar threads

  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 18 ·
Replies
18
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 65 ·
3
Replies
65
Views
8K
  • · Replies 9 ·
Replies
9
Views
3K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 1 ·
Replies
1
Views
4K