Options when using the ode23/45 solver

  • Thread starter Hansi87
  • Start date
  • Tags
    Options
In summary, the conversation discusses the use of Options and the event function in a script for calculating ray paths in the subsurface using kinematic ray tracing. The goal is to specify borders for when the ode23 function should stop, such as reaching the border of the grid or the surface Z = 0. The individual is seeking guidance on how to implement the event function to achieve this.
  • #1
Hansi87
2
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
  • #2
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.
 

Related to Options when using the ode23/45 solver

1. What is the difference between ode23 and ode45?

The main difference between ode23 and ode45 is the order of the numerical method used for solving the differential equations. Ode23 uses a second and third order Runge-Kutta method, while ode45 uses a fourth and fifth order Runge-Kutta method. This means that ode45 is more accurate but also more computationally expensive than ode23.

2. Can I use ode23/45 to solve stiff systems?

Yes, ode23/45 can be used to solve stiff systems. However, it is generally recommended to use ode15s for stiff systems, as it is specifically designed for this type of problem.

3. How do I specify initial conditions for ode23/45?

The initial conditions for ode23/45 can be specified by passing them as a vector to the initial conditions parameter of the solver function. The order of the vector should correspond to the order of the equations in the differential system.

4. Can I use ode23/45 for solving systems with discontinuities?

Yes, ode23/45 can be used for solving systems with discontinuities. However, it is important to note that the solver may not handle these discontinuities accurately, and the results should be carefully validated.

5. How do I choose between ode23 and ode45 for my problem?

The choice between ode23 and ode45 depends on the specific characteristics of your problem. If you require a higher level of accuracy, ode45 may be a better choice. However, if your problem is not too stiff and requires less computational resources, ode23 can be a more efficient option.

Similar threads

  • Classical Physics
Replies
2
Views
1K
  • Mechanical Engineering
Replies
2
Views
1K
  • Programming and Computer Science
Replies
4
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
6
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
10K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
5K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • Calculus and Beyond Homework Help
Replies
1
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
3K
Replies
3
Views
3K
Back
Top