diffrential equation using ode45
Show older comments
how to solve this diffrential equation using ode45
function dxdt = decoherence1nv(t,x,del,delt)
xm = interp1(delt,del,t);
dxdt = zeros(4,1);
a=0.04; Q=0.5;e=0.1;z=pi/3;w=1;
dxdt(1) = -a .* x(1) + 1i .*0.5.* e .* Q .* sin(z) .* x(2) - 1i.*0.5.* e .* Q .* sin(z) .* x(3) ;
dxdt(2) = 1i .*0.5.* e .* Q .* sin(z).* x(1) - 1i .* w .* x(2) - 0.5 .* a .* x(2) -1i .* e .* Q .* cos(z) .* x(2) - 1i .*0.5.* e .* Q .* sin(z) .* x(4) ;
dxdt(3) = -1i .*0.5* e .* Q .* sin(z) .* x(1) + 1i .* w .* x(3) - 0.5 .* a .* x(3) + 1i .* e .* Q .* cos(z) .* x(3) + 1i.*0.5* e .* Q .* sin(z) .* x(4) ;
dxdt(4) = a .* x(1) - 1i .*0.5* e .* Q .* sin(z) .* x(2) + 1i .*0.5* e .* Q .* sin(z) .* x(3);
end
12 Comments
Walter Roberson
on 18 Dec 2019
What problem are you running into?
xm = interp1(delt,del,t);
That would typically introduce discontinuities in the calculations. You should be breaking the single ode45() call over the timespan, into one call for each different boundary of delt, so that you would not have discontinuities in the second derivative.
Or rather you would do that if not for the fact that you do not use xm in your calculation.
abhishek singh
on 18 Dec 2019
abhishek singh
on 18 Dec 2019
abhishek singh
on 18 Dec 2019
Walter Roberson
on 18 Dec 2019
I do not understand what you mean by "dont take xm" ?
Please show your ode45() call.
abhishek singh
on 18 Dec 2019
abhishek singh
on 18 Dec 2019
abhishek singh
on 18 Dec 2019
Walter Roberson
on 18 Dec 2019
What is ou_seq ?
abhishek singh
on 18 Dec 2019
Walter Roberson
on 18 Dec 2019
I do not understand the problem. The code does not produce any error messages when it is run, and after the code, x is already in the form [x(:1),x(:2);x(:3),x(:4)] so I do not know what you are looking for.
Your ou_seq function should not be ignoring its inputs.
Using interp1() to calculate xm would be a discontinuity problem in your decoherence1nv function, except that that function ignores xm after it calculates it.
The ode*() series of function calls estimate gradient and hessian, and in order to do that, the function behaviour must be continuous to two derivatives within the time range that is being calculated over. If you use w=1+xm then you would be violating that condition at every delt boundary. You need to rewrite the code to make separate ode*() calls over time range delt(1:2), delt(2:3), delt(3:4) and so on.
abhishek singh
on 18 Dec 2019
Answers (1)
Walter Roberson
on 18 Dec 2019
current_x0 = x0;
for idx = 1:length(delt)-1
ts = delt(idx); te = delt(idx+1); tm = (ts+te)/2;
[part_t{idx},part_x{idx}] = ode113(@(t,x)decoherence1nv(t,x,del,delt),[ts,dm,te],current_x0);
current_x0 = part_x{idx}(end,:);
end
SkipFirst = @(V) V(2:end,:);
t = [part_t{1}{1}; cell2mat(cellfun(SkipFirst, part_t, 'uniform', 0))];
x = [part_x{1}(1,:); cell2mat(cellfun(SkipFirst, part_x, 'uniform', 0))];
7 Comments
abhishek singh
on 18 Dec 2019
Walter Roberson
on 18 Dec 2019
ode113() is permitted to produce invalid results when you ask it to calculate across a discontinuity.
At the moment, I do not see any mathematical reason why trace(rht) should ever be 1.
abhishek singh
on 18 Dec 2019
abhishek singh
on 21 Dec 2019
abhishek singh
on 21 Dec 2019
Walter Roberson
on 21 Dec 2019
Is there any other way to add noise without using interpolation method in this code .
Yes, there is.
As I indicated before, the interpolation you are doing introduces discontinuities in the Hessian, and because that is not permitted, you need to break the calculation up into segments in which there is no discontinuity.
With there not being any discontinuity, instead of using interp1(), you can pass in the information you need to do the interpolation yourself. You would need to know the base time of this segment, and the base noise, xm(K), and the slope m=(xm(K+1)-xm(K))/delta_t . The interpolation would then be (t-base_t) * slope + base_noise, which would be faster than calling interp1()
Walter Roberson
on 21 Dec 2019
Note also that in theory you could fit a degree 4+2=6 or higher polynomial to the noise and use the fitted data with interp1(): if you were to do that, then the theoretical problems about the noise giving discontinuous hessians would not apply. However, a degree N polynomial would of course have at most ceil(N/2) peaks, and degree 7 is probably about the maximum polynomial order that is reasonably numerically stable, so I doubt that it would be an acceptable model of your physics to fit your noise to degree 6 to 8, so you will probably need to split the timespan like I discussed earlier.
Categories
Find more on Correlation and Convolution in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!