There used to be a function RefineMesh in Matlab used in solving ODE's, but it is now used for PDE's and isn't the same function. Is there a new function for the old purpose?
조회 수: 1(최근 30일)
I'm looking at a textbook on Matlab, at the author used RefineMesh to define a time variable when solving an ODE using ode45. When I tried to run the code on my matlab, it said it didn't recognize RefineMesh. Did the name of the function change? I included the example below.
f = @(t,x) t.ˆ2 + x - x.ˆ4/10;
sol = ode45( f, [0,5], 0 );
% Compute and plot the relative residual on a lot of points
t = RefineMesh( sol.x, 40 );
[ z, dotz ] = deval(sol,t);
deltat = dotz./f(t,z)-1;
figure(1),semilogy(t,abs(deltat),'k.'),set(gca,'fontsize',24) xlabel('t'),ylabel('relative residual'),axis([0,5,1.0e-8,1.0])
J. Alex Lee 2021년 11월 23일
The workflow above only re-evaluates the "static" solution of ode45 at more data points by an interpolation scheme consistent with the ode45 discretization...you can achieve similar result by just calling ode45 with ode options with the "Refine" option set to some large value that gives you a satisfactory spacing.
There is a difference from running ode45 with tighter tolerances, which, all else equal, would force it to take smaller steps and thus in consequence your mesh will be more refined - but the answer would be different (more accurate) than "refining" the x-resolution after-the-fact.
Finally, a simple way to accomplish what you want might be to just split the differences equally in your x-vector (find all mid-points of you rexisting grid and include them). You could do something like
x = [1 2 4 7 9 10 11]
NOld = numel(x);
% node splitting
s = x(1:end-1) + diff(x)/2;
t = reshape([x;[s,NaN]],1,);
t = t(1:end-1)
Or if you don't care about having the original nodes and want to refine with arbitrarily many new nodes, something like
% refine with arbitrarily many nodes
z = linspace(0,1,NOld);
NNew = 2*NOld;
t = interp1(z,x,linspace(0,1,NNew));
These solutions may not be the best, but hope can get you started.