MATLAB Answers

How to restrict the domain of dependent variable in ode45

88 views (last 30 days)
Mahdi Khalili Hezarjaribi
Mahdi Khalili Hezarjaribi on 31 Jul 2020 at 10:47
Commented: Mahdi Khalili Hezarjaribi on 3 Aug 2020 at 17:16
Hello every one
I have this equation of ray evolution that I want to solve in matlab using ode45
where dn2 / dx equals to n * (dn / dx) and n is a function of x as n(x). n is the refractive index in Optics and this equation shows how the ray evolves in a medium of height x and range z.
β is a constant and existing, but here is my problem: I do not have the explicit form of n(x), instead, I have a data set of n for x = (0,30). How can I solve this equation using ode45, or any other method compatible for this problem, in a way that the dependent variable x is considered between 0 to 30, because my n varibales are bound only to this interval, so that I would only substitute the n variables and rest assured that x is changing according to n. n is a 1 * 300 matrix by the way


Mahdi Khalili Hezarjaribi
Mahdi Khalili Hezarjaribi on 2 Aug 2020 at 17:04
I answered your question in the commnets but maybe it was vague. I am sorry for my mistake. I have already attached my function (called n_func.m generating n(x)) and Main.m (calling n_func.m) which solves the equation. (I attached them again on this comment).
Let me explain from the scratch (and according to my code):
This is my equation:
here, z is the dependent variable (height) and x is the independent one (range). the purpose of the code is to simulate the ray path in the vicinty of the sea surface (for each point at range x and height z and for different angle of incident light which in the code are shown as i1); In optics, it is not traditionally convincing to say, for instance, z is a function of x and I completely understand what you mean because it is really not, but the equation implies that for tracing the ray, we have to consider such situation as if z is a function of x.
we do not have the explicit form of n(z) as a function (no polynimialor transcedental form); instead, we are going to obtain it numerically from the function n_func.m for z = (0.1,30). It means that, for every z, there will be a n(z). in this function, we discretized z to 300 points, so n(z) would be 300 points as well and n is n(z(x)). we can not set z = 0 becuase we have some logarithmic restriction, so we have to start from z = 0.1 or eps. Having n(z) at hand, we want to solve the equation above for x = (0,10000), and we want to start ray tracing at z(0) = 10 (which is our initial condition in the equation).
Considering these, How can I solve this equation to get the right answer? I already proposed a very naive and simple algorithm which it seems to be wrong.
You also asked "Is there reason to believe that z(x) passes through the area over which you know some n values? ". that is my quaestion too to be honest. In fact I have no opinion if your question is necessary to solve this problem or not but I believe that your doubt might be right and we maybe need to extrapolate n, yet I insist that I am not sure.
Thank you for your attention so far and I am very happy that you followed up until now. If anyother information needed, I am at your service.
J. Alex Lee
J. Alex Lee on 3 Aug 2020 at 11:22
You have now flipped x's and z's so many times it's hard to know what's what. It seems Walter's question is the most pertinent.
If you have no reason to believe your solution will be bound to the range (0.1,30), then I would say simply test it a posteriori. Follow James's advice to interpolate, and see if your algorithm fails because you try to evaluate n(z) at some value outside the range.
At least for z>30, I've observed that you can probably safely extrapolate linearly.
If you know the asymptotic form of as , you could piece-wise define n(z) as an interpolant from , analytic form for , and linear from .
If β value is less than the trough-like feature in you will likely have no issues, as this will guarantee your derivative to be positive so that .

Sign in to comment.

Answers (0)