Options when using the ode23/45 solver

  • Thread starter Thread starter Hansi87
  • Start date Start date
  • Tags Tags
    Options
Click For Summary
SUMMARY

The discussion focuses on utilizing the ode23 solver in MATLAB for kinematic ray tracing within a 2D velocity model grid. The user seeks to implement event functions to halt the solver when the ray reaches the surface (Z = 0) or exits the grid boundaries in the X direction. The current implementation uses conditional statements to manage these events, but the user aims for a more elegant solution by leveraging MATLAB's event handling capabilities. The conversation highlights the need for a clearer understanding of event functions in the context of ODE solvers.

PREREQUISITES
  • Familiarity with MATLAB programming and syntax
  • Understanding of ordinary differential equations (ODEs)
  • Knowledge of kinematic ray tracing principles
  • Experience with MATLAB's ode23 function and its options
NEXT STEPS
  • Research how to implement event functions in MATLAB's ode23 solver
  • Explore examples of using event functions to manage ODE termination conditions
  • Learn about MATLAB's interpolation functions, specifically interp2
  • Investigate best practices for optimizing ODE functions for performance
USEFUL FOR

Researchers and engineers involved in geophysical modeling, MATLAB users working with ODE solvers, and developers focused on improving computational efficiency in ray tracing algorithms.

Hansi87
Messages
2
Reaction score
0
hi

I'm making a script for calculating ray paths in the subsurface using kinematic ray tracing.
To my disposition I have a velocity model given on a 2D grid.

I'm having troubles understanding how to use Options in order to specify the borders for when the ode23 function is supposed to stop(which is when it reaches the border of the grid).

At the moment i use the following:
[t,f] = ode23('raytrace', [0 10],[x0,z0,px0,pz0]);function dz =raytrace(t,z)
global v dx dz

dz = zeros(4,1);
if z(2) < 0;
vel = interp2(3.5:0.01:20,0:-0.01:-10,v,z(1),z(2),'*linear');
v2 = vel^2;
v1 = 1/vel;
vx = interp2(3.5:0.01:20,0:-0.01:-10,dx,z(1),z(2),'*linear');
vz = interp2(3.5:0.01:20,0:-0.01:-10,dz,z(1),z(2),'*linear');
dz(1) = v2*z(3);
dz(2) = v2*z(4);
dz(3) = -v1*vx;
dz(4) = -v1*vz;
elseif z(2) > 0;
return
end
end

My goal is to not have to use the if/else if sentence in order to make it a bit more elegant.

ty in advance
 
Last edited:
Physics news on Phys.org
I'm aware that my first post was slightly unclear and it was not easy to understand what I meant.

I want to set an event so that when the ray I shoot reaches the surface Z = 0 the ODE function stops.

I also want to implement the event so that it stops if the ray travels outside the grid in the x direction.

I know I need to use the event function but I'm unable to comprehend how to use it even after reading examples.

I would really appreciate some help in this matter.

Thanks in advance.
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 5 ·
Replies
5
Views
10K
  • · Replies 5 ·
Replies
5
Views
6K
  • · Replies 1 ·
Replies
1
Views
2K
Replies
1
Views
4K
Replies
3
Views
3K
Replies
1
Views
3K