Questions tagged [ode45]
140 questions
0
votes
1 answer
Python ODE45 IndexError: list assignment out of range
I am trying to duplicate an ODE script I have running in Matlab to Python. Here is the Matlab script:
t0 = 0;
tfinal = 25;
q1 = 1;
q2 = 1;
q1dot = 0;
q2dot = 0;
% ODE variables
times = [t0 tfinal];
stateVars=[q1 q1dot q2 q2dot];
% ODE45
options =…

RocketSocks22
- 391
- 1
- 4
- 20
0
votes
0 answers
Plotting three functions in the same output
I've defined the function
function dzdt=odefun2222(t,z)
beta=1+exp(-t); delta=1+exp(-t); rho=1+exp(-t);
gama=exp(-t); theta=exp(-t);
f1=1/2+1/(t+1);…

Cris
- 103
- 4
0
votes
1 answer
Plotting a function on a specified domain
I am trying to plot the solution of a system of ODEs.
The code is:
tspan = [0 10];
z0 = [0.01 0.01 0.01 0.01];
[t,z] = ode45(@(t,z) odefun3(t,z), tspan, z0);
plot(z(:,3))
Why the output is plotted on the interval [0,60] and not on [0,10],…

Cris
- 103
- 4
0
votes
1 answer
Plotting a function defined by a system of ODEs with MATLAB
I am trying to solve with MATLAB the first order ODEs system,
$$\left\{
\begin{array}{l}
x_{1}^{\prime }=-\frac{1}{t+1}x_{1}+x_{2} \\
x_{2}^{\prime }=-(1+e^{-2t})x_{1}-\frac{1}{t+1}x_{2}+\frac{e^{-3t}}{t+1}x_{3}
\\
x_{3}^{\prime…

Cris
- 103
- 4
0
votes
1 answer
Matlab: other odes are working, except ode45 I need- why?
I've got the following script:
h=[0.01 0.05 0.1 0.5 1];
func = @(t, y) -2*y+t*sin(t);
opts = odeset('Reltol',1e-13,'AbsTol',1e-14,'Stats','on');
f1_f2_matrix = [];
sinus=@(t) t*(sin(t));
error2nd = zeros(length(h),1);
errorInf =…

Marta
- 37
- 10
0
votes
0 answers
I cannot solve this equatition, using ode45 in Matlab
dθ/dτ=-θ-b*θ^4
I need to solve this equation by ode45
I tried the following way but I dont sure if it is true
[t,a]=ode45('fonks', [0 120], 1)
plot (t,a)
function x=fonks(t,a)
b=0.5;
x=-t+b*t^4;

mzatmaca
- 1
0
votes
1 answer
Is it possible to trigger event by non-continuous function?
Can someone please point me in the right direction with specifying an event for a function that is not continuous? For example, suppose that I have Object1 that moves along the x axis and I also have another Object2 that moves vertically at x=100.
I…

Razvan
- 151
- 4
- 14
0
votes
1 answer
Setting up two events with ode45
Could someone please explain what am I doing wrong when setting up an ode45 event this way?
When I tried running the code it would reach line 6, however it would not stop computing the ode regardless that I set isTerminal=[1,1] on line 7, instead it…

Razvan
- 151
- 4
- 14
0
votes
1 answer
Setting Up ODE45 Function
This might be a trivial question, but I need help setting up the following ODE to be solved with ODE45:
4x" + 32x' + 60x = 3f'(t) + 2f(t), with initial conditions x(0) = 0, x'(0) = 0, and f(t) = 5t, from t = 0 to t = 1.5
Making substitutions, I end…

Naman Shah
- 35
- 5
0
votes
1 answer
Variable undefined in simple matlab function
I cannot understand why I am receiving the following error:
error: 'y' undefined near line 7 column 22
error: execution exception in odefun.m
For this function:
function s = odefun(t, y)
global K = [ 0.5; 3; 1; 4; 1; 5 ];
function…

jaslibra
- 131
- 9
0
votes
1 answer
Spring/Damper Calculation & Plotting
Given two systems with damper/spring:
First system's simulink model with step time 2, final value 0.5:
Simulink of the second system with same input:
I have to find the code using dsolve and ode45 to generate the same graph with Simulink. Given…

S. Seo
- 11
- 1
- 5
0
votes
0 answers
Animating circles, based on ODE-solver output in Matlab
I am new to Matlab and am trying to animate several spheres moving along a straight line based on both, initial speed and position.
I have gotten the ode45 solver to spit out velocity and displacement plots for me (over time) and would now like to…

Da Spotz
- 200
- 2
- 16
0
votes
0 answers
I am trying to write this function for ode. But it always gives me an error as not enough input arguments. Here is my code associated:
I have written this code as my function code for third order differential ODE. I am continuously getting the same error as not enough input arguments.
function dxdt = odefcn(t,x,a) %Function name
dxdt = zeros(3,1);
dxdt(1) = x(2);
…

emma19
- 57
- 2
- 7
0
votes
1 answer
Matlab ODE45 nonliear must return a column vector
function yp = nonlinear(t,y)
e=0.2;
yp(1)=y(2);
yp(2) = (-y(1)-e*y(1)^3);
code
tspan = [0 20];
y0=[0;0]
[t,y]=ode45('nonlinear',tspan,y0)
plot (t,y(:,1))
grid
xlabel('time')
ylabel('u')
title ('u vs. t')
hold on;
When I execute this, it says…
user2086751
0
votes
1 answer
Matlab ode45 help undefined variable
function yp = nonlinear (t,y)
e=0.2;
yp(1)=y(2);
yp(2) = (-y(1)-e*y(1)^3);
tspan = [0.20];
y0=[0;0]
[t,y]=ode45('nonlinear',tpsan,y0)
plot (t,y(:,1))
grid
xlabel('time')
ylabel('u')
title ('u vs. t')
hold on;
Sorry I am absolutely noob at matlab,…
user2086751