Is it possible to solve this differential equation by modifying a given algorithm?

Hello everyone,
Sorry for bothering with a similar problem (https://www.mathworks.com/matlabcentral/answers/2031639-is-there-a-possibility-to-solve-this-equation-numerically-using-matlab?s_tid=srchtitle) which was previously resolved by a user named Torsten. I am now trying to solve this final version of differential equation using MATLAB (r and u are variables):
The code used for solving this equation:
u0 = 0;
u0dot = 0.001;
u0ddot = 1; % Estimate
t0 = 0;
y0 = [u0,u0dot,u0ddot];
s = @(x)Ode(t0,[y0(1:2),x]);
h = @(x) subsref(s(x), struct('type', '()', 'subs', {{3}}));
sol = fsolve(h,y0(3),optimset('TolFun',1e-10,'TolX',1e-10))
y0 = [y0(1:2),sol];
tspan = [t0,1];
OdeFcn = @Ode;
Mass = [1 0 0;0 1 0;0 0 0];
options = odeset('RelTol',1e-10,'AbsTol',1e-10,'Mass',Mass,'InitialStep',1e-10);
[X,Y] = ode15s(@Ode,tspan,y0,options);
figure(1)
plot(X,[Y(:,1),Y(:,2)])
for i = 1:numel(X)
dydx = Ode(X(i),Y(i,:));
res3(i) = dydx(3);
end
figure(2)
plot(X,res3.')
function dydx = Ode(x,y)
persistent iter
if isempty(iter)
iter = 0;
end
iter = iter + 1;
if mod(iter,10000)==0
iter = 0;
x
end
Ecm = 33787;
d = 0.02;
R = 0.085;
Ac = 0.02;
S = 54;
C = 750;
Gcm = 14000;
dydx = zeros(3,1);
dydx(1) = y(2);
dydx(2) = y(3);
fun = @(r) y(3)*S*Ecm./r/(8*(S+C)).*(4*Ac/pi-4*r.^2+d^2)./(Gcm-2223.5*y(3)*S*Ecm./r/(8*(S+C)).*(4*Ac/pi-4*r.^2+d^2));
dydx(3) = y(1) - integral(fun,d/2,R,'AbsTol',1e-10,'RelTol',1e-10);
end
It seems to me that the equation is stiff so with each iteration I am constantly getting this error: Warning: Reached the limit on the maximum number of intervals in use. Approximate bound on error is... The integral may not exist, or it may be difficult to approximate numerically to the requested accuracy. Maybe it is impossible to solve this equation numerically using MATLAB? And once again, thank you for your answers.

 채택된 답변

Torsten
Torsten 2023년 10월 11일
편집: Torsten 2023년 10월 11일
Seems your function to be integrated has a singularity between d/2 and R. Applying "integral" in this case is almost impossible. It has nothing to do with "stiffness".
Ecm = 33787;
d = 0.02;
R = 0.085;
Ac = 0.02;
S = 54;
C = 750;
Gcm = 14000;
fun = @(r,y3) y3*S*Ecm./r/(8*(S+C)).*(4*Ac/pi-4*r.^2+d^2)./(Gcm-2223.5*y3*S*Ecm./r/(8*(S+C)).*(4*Ac/pi-4*r.^2+d^2));
y3 = 0:0.1:2;
hold on
for i=1:numel(y3)
plot(linspace(d/2,R,1000),fun(linspace(d/2,R,1000),y3(i)))
end
hold off

댓글 수: 4

I am quite a beginner in MATLAB. Correct me if I am wrong, so this graph shows changing singularity position at some point r with respect to changing u''(x) value?
Torsten
Torsten 2023년 10월 11일
편집: Torsten 2023년 10월 11일
Yes, the location of the singularity depends on the value of u''(x) (and maybe the singularity in the r-interval disappears if u''(x) is different from 0 <= u''(x) <= 2 ; I didn't check it in detail).
You could theoretically find the zeros of the denominator as a function of u''(x) and see what values for u''(x) are allowed for that the zeros are outside the interval [d/2 , R]. But I don't know if this helps in the solution of the above problem because u'' follows from u and u' - you cannot prescribe it, of course.
I used Symbolic Math Toolbox to solve the integral and I got a ginormous equation (It is strange, that when I insert u''(x) = 0, I get NaN+NaNi which is not true when compared to the original equation which gives the value of 0). I noticed that as u''(x) approaches an approximate value of .0087 the u(x) instantaneously approaches to 1.5590e-04 which for certain (small) u'(0) and x values could work. In these cases, I guess that the differential equation could be solved using foward Euler method by guessing u''(x) values which correspond to u(x), but at some point the steps should be infinitesimally small.
The code for u(x)-u''(x) relationship up to a critical point:
Ecm = 33787;
Gcm = 14000;
d = 0.02;
R = 0.085;
Ac = 0.02;
S = 54;
C = 750;
i = 1;
d2u = 0:0.0000001:0.0087167267434218763041964272986;
f = @ (d2u) d/4447 + (log(16*pi*Gcm^2*S^2 - (3991211251234741*C*Gcm*(16*pi*C^2*Gcm^2 + 32*pi*C*Gcm^2*S + (8338616764825809*Ecm^2*S^2*d^2*d2u^2)/134217728 + 79103236*Ac*Ecm^2*S^2*d2u^2 + 16*pi*Gcm^2*S^2)^(1/2))/562949953421312 - (3991211251234741*Gcm*S*(16*pi*C^2*Gcm^2 + 32*pi*C*Gcm^2*S + (8338616764825809*Ecm^2*S^2*d^2*d2u^2)/134217728 + 79103236*Ac*Ecm^2*S^2*d2u^2 + 16*pi*Gcm^2*S^2)^(1/2))/562949953421312 + 16*pi*C^2*Gcm^2 + (8338616764825809*Ecm^2*S^2*d^2*d2u^2)/134217728 - (108235050608926760152013457518649379*Ecm*S*d2u*(16*pi*C^2*Gcm^2 + 32*pi*C*Gcm^2*S + (8338616764825809*Ecm^2*S^2*d^2*d2u^2)/134217728 + 79103236*Ac*Ecm^2*S^2*d2u^2 + 16*pi*Gcm^2*S^2)^(1/2))/81129638414606681695789005144064 + 79103236*Ac*Ecm^2*S^2*d2u^2 + 32*pi*C*Gcm^2*S)*(Ecm^2*(4*Gcm*pi*S^3*d^2*d2u^2 + 16*Ac*Gcm*S^3*d2u^2 + 4*C*Gcm*pi*S^2*d^2*d2u^2 + 16*Ac*C*Gcm*S^2*d2u^2) + (64*pi*Gcm^3*S^3)/19775809 - (3991211251234741*C^2*Gcm^2*(16*pi*C^2*Gcm^2 + 32*pi*C*Gcm^2*S + (8338616764825809*Ecm^2*S^2*d^2*d2u^2)/134217728 + 79103236*Ac*Ecm^2*S^2*d2u^2 + 16*pi*Gcm^2*S^2)^(1/2))/2783197688854690660352 - (3991211251234741*Gcm^2*S^2*(16*pi*C^2*Gcm^2 + 32*pi*C*Gcm^2*S + (8338616764825809*Ecm^2*S^2*d^2*d2u^2)/134217728 + 79103236*Ac*Ecm^2*S^2*d2u^2 + 16*pi*Gcm^2*S^2)^(1/2))/2783197688854690660352 + (64*pi*C^3*Gcm^3)/19775809 + (192*pi*C*Gcm^3*S^2)/19775809 + (192*pi*C^2*Gcm^3*S)/19775809 - (3991211251234741*C*Gcm^2*S*(16*pi*C^2*Gcm^2 + 32*pi*C*Gcm^2*S + (8338616764825809*Ecm^2*S^2*d^2*d2u^2)/134217728 + 79103236*Ac*Ecm^2*S^2*d2u^2 + 16*pi*Gcm^2*S^2)^(1/2))/1391598844427345330176))/(16*pi*C^2*Ecm*Gcm^2*S*d2u + 32*pi*C*Ecm*Gcm^2*S^2*d2u + (8338616764825809*Ecm^3*S^3*d^2*d2u^3)/134217728 + 79103236*Ac*Ecm^3*S^3*d2u^3 + 16*pi*Ecm*Gcm^2*S^3*d2u) + (log(16*pi*Gcm^2*S^2 + (3991211251234741*C*Gcm*(16*pi*C^2*Gcm^2 + 32*pi*C*Gcm^2*S + (8338616764825809*Ecm^2*S^2*d^2*d2u^2)/134217728 + 79103236*Ac*Ecm^2*S^2*d2u^2 + 16*pi*Gcm^2*S^2)^(1/2))/562949953421312 + (3991211251234741*Gcm*S*(16*pi*C^2*Gcm^2 + 32*pi*C*Gcm^2*S + (8338616764825809*Ecm^2*S^2*d^2*d2u^2)/134217728 + 79103236*Ac*Ecm^2*S^2*d2u^2 + 16*pi*Gcm^2*S^2)^(1/2))/562949953421312 + 16*pi*C^2*Gcm^2 + (8338616764825809*Ecm^2*S^2*d^2*d2u^2)/134217728 + (108235050608926760152013457518649379*Ecm*S*d2u*(16*pi*C^2*Gcm^2 + 32*pi*C*Gcm^2*S + (8338616764825809*Ecm^2*S^2*d^2*d2u^2)/134217728 + 79103236*Ac*Ecm^2*S^2*d2u^2 + 16*pi*Gcm^2*S^2)^(1/2))/81129638414606681695789005144064 + 79103236*Ac*Ecm^2*S^2*d2u^2 + 32*pi*C*Gcm^2*S)*(Ecm^2*(4*Gcm*pi*S^3*d^2*d2u^2 + 16*Ac*Gcm*S^3*d2u^2 + 4*C*Gcm*pi*S^2*d^2*d2u^2 + 16*Ac*C*Gcm*S^2*d2u^2) + (64*pi*Gcm^3*S^3)/19775809 + (3991211251234741*C^2*Gcm^2*(16*pi*C^2*Gcm^2 + 32*pi*C*Gcm^2*S + (8338616764825809*Ecm^2*S^2*d^2*d2u^2)/134217728 + 79103236*Ac*Ecm^2*S^2*d2u^2 + 16*pi*Gcm^2*S^2)^(1/2))/2783197688854690660352 + (3991211251234741*Gcm^2*S^2*(16*pi*C^2*Gcm^2 + 32*pi*C*Gcm^2*S + (8338616764825809*Ecm^2*S^2*d^2*d2u^2)/134217728 + 79103236*Ac*Ecm^2*S^2*d2u^2 + 16*pi*Gcm^2*S^2)^(1/2))/2783197688854690660352 + (64*pi*C^3*Gcm^3)/19775809 + (192*pi*C*Gcm^3*S^2)/19775809 + (192*pi*C^2*Gcm^3*S)/19775809 + (3991211251234741*C*Gcm^2*S*(16*pi*C^2*Gcm^2 + 32*pi*C*Gcm^2*S + (8338616764825809*Ecm^2*S^2*d^2*d2u^2)/134217728 + 79103236*Ac*Ecm^2*S^2*d2u^2 + 16*pi*Gcm^2*S^2)^(1/2))/1391598844427345330176))/(16*pi*C^2*Ecm*Gcm^2*S*d2u + 32*pi*C*Ecm*Gcm^2*S^2*d2u + (8338616764825809*Ecm^3*S^3*d^2*d2u^3)/134217728 + 79103236*Ac*Ecm^3*S^3*d2u^3 + 16*pi*Ecm*Gcm^2*S^3*d2u) - (log(16*pi*Gcm^2*S^2 - (3991211251234741*C*Gcm*(16*pi*C^2*Gcm^2 + 32*pi*C*Gcm^2*S + (8338616764825809*Ecm^2*S^2*d^2*d2u^2)/134217728 + 79103236*Ac*Ecm^2*S^2*d2u^2 + 16*pi*Gcm^2*S^2)^(1/2))/562949953421312 - (3991211251234741*Gcm*S*(16*pi*C^2*Gcm^2 + 32*pi*C*Gcm^2*S + (8338616764825809*Ecm^2*S^2*d^2*d2u^2)/134217728 + 79103236*Ac*Ecm^2*S^2*d2u^2 + 16*pi*Gcm^2*S^2)^(1/2))/562949953421312 + 16*pi*C^2*Gcm^2 + (8338616764825809*Ecm^2*S^2*d^2*d2u^2)/134217728 + 79103236*Ac*Ecm^2*S^2*d2u^2 + 32*pi*C*Gcm^2*S - (17748916434240893227*Ecm*S*d*d2u*(16*pi*C^2*Gcm^2 + 32*pi*C*Gcm^2*S + (8338616764825809*Ecm^2*S^2*d^2*d2u^2)/134217728 + 79103236*Ac*Ecm^2*S^2*d2u^2 + 16*pi*Gcm^2*S^2)^(1/2))/2251799813685248)*(Ecm^2*(4*Gcm*pi*S^3*d^2*d2u^2 + 16*Ac*Gcm*S^3*d2u^2 + 4*C*Gcm*pi*S^2*d^2*d2u^2 + 16*Ac*C*Gcm*S^2*d2u^2) + (64*pi*Gcm^3*S^3)/19775809 - (3991211251234741*C^2*Gcm^2*(16*pi*C^2*Gcm^2 + 32*pi*C*Gcm^2*S + (8338616764825809*Ecm^2*S^2*d^2*d2u^2)/134217728 + 79103236*Ac*Ecm^2*S^2*d2u^2 + 16*pi*Gcm^2*S^2)^(1/2))/2783197688854690660352 - (3991211251234741*Gcm^2*S^2*(16*pi*C^2*Gcm^2 + 32*pi*C*Gcm^2*S + (8338616764825809*Ecm^2*S^2*d^2*d2u^2)/134217728 + 79103236*Ac*Ecm^2*S^2*d2u^2 + 16*pi*Gcm^2*S^2)^(1/2))/2783197688854690660352 + (64*pi*C^3*Gcm^3)/19775809 + (192*pi*C*Gcm^3*S^2)/19775809 + (192*pi*C^2*Gcm^3*S)/19775809 - (3991211251234741*C*Gcm^2*S*(16*pi*C^2*Gcm^2 + 32*pi*C*Gcm^2*S + (8338616764825809*Ecm^2*S^2*d^2*d2u^2)/134217728 + 79103236*Ac*Ecm^2*S^2*d2u^2 + 16*pi*Gcm^2*S^2)^(1/2))/1391598844427345330176))/(16*pi*C^2*Ecm*Gcm^2*S*d2u + 32*pi*C*Ecm*Gcm^2*S^2*d2u + (8338616764825809*Ecm^3*S^3*d^2*d2u^3)/134217728 + 79103236*Ac*Ecm^3*S^3*d2u^3 + 16*pi*Ecm*Gcm^2*S^3*d2u) - (log(16*pi*Gcm^2*S^2 + (3991211251234741*C*Gcm*(16*pi*C^2*Gcm^2 + 32*pi*C*Gcm^2*S + (8338616764825809*Ecm^2*S^2*d^2*d2u^2)/134217728 + 79103236*Ac*Ecm^2*S^2*d2u^2 + 16*pi*Gcm^2*S^2)^(1/2))/562949953421312 + (3991211251234741*Gcm*S*(16*pi*C^2*Gcm^2 + 32*pi*C*Gcm^2*S + (8338616764825809*Ecm^2*S^2*d^2*d2u^2)/134217728 + 79103236*Ac*Ecm^2*S^2*d2u^2 + 16*pi*Gcm^2*S^2)^(1/2))/562949953421312 + 16*pi*C^2*Gcm^2 + (8338616764825809*Ecm^2*S^2*d^2*d2u^2)/134217728 + 79103236*Ac*Ecm^2*S^2*d2u^2 + 32*pi*C*Gcm^2*S + (17748916434240893227*Ecm*S*d*d2u*(16*pi*C^2*Gcm^2 + 32*pi*C*Gcm^2*S + (8338616764825809*Ecm^2*S^2*d^2*d2u^2)/134217728 + 79103236*Ac*Ecm^2*S^2*d2u^2 + 16*pi*Gcm^2*S^2)^(1/2))/2251799813685248)*(Ecm^2*(4*Gcm*pi*S^3*d^2*d2u^2 + 16*Ac*Gcm*S^3*d2u^2 + 4*C*Gcm*pi*S^2*d^2*d2u^2 + 16*Ac*C*Gcm*S^2*d2u^2) + (64*pi*Gcm^3*S^3)/19775809 + (3991211251234741*C^2*Gcm^2*(16*pi*C^2*Gcm^2 + 32*pi*C*Gcm^2*S + (8338616764825809*Ecm^2*S^2*d^2*d2u^2)/134217728 + 79103236*Ac*Ecm^2*S^2*d2u^2 + 16*pi*Gcm^2*S^2)^(1/2))/2783197688854690660352 + (3991211251234741*Gcm^2*S^2*(16*pi*C^2*Gcm^2 + 32*pi*C*Gcm^2*S + (8338616764825809*Ecm^2*S^2*d^2*d2u^2)/134217728 + 79103236*Ac*Ecm^2*S^2*d2u^2 + 16*pi*Gcm^2*S^2)^(1/2))/2783197688854690660352 + (64*pi*C^3*Gcm^3)/19775809 + (192*pi*C*Gcm^3*S^2)/19775809 + (192*pi*C^2*Gcm^3*S)/19775809 + (3991211251234741*C*Gcm^2*S*(16*pi*C^2*Gcm^2 + 32*pi*C*Gcm^2*S + (8338616764825809*Ecm^2*S^2*d^2*d2u^2)/134217728 + 79103236*Ac*Ecm^2*S^2*d2u^2 + 16*pi*Gcm^2*S^2)^(1/2))/1391598844427345330176))/(16*pi*C^2*Ecm*Gcm^2*S*d2u + 32*pi*C*Ecm*Gcm^2*S^2*d2u + (8338616764825809*Ecm^3*S^3*d^2*d2u^3)/134217728 + 79103236*Ac*Ecm^3*S^3*d2u^3 + 16*pi*Ecm*Gcm^2*S^3*d2u) - 5616799203107659/147573952589676412928; % This is the solution for the integral
vpa(f(0.0087167267434218763041964272986),100)
while i <= 0.0087167267434218763041964272986/0.0000001 + 1
a(i) = f(d2u(i));
i=i+1;
end
plot(d2u,a)
Torsten
Torsten 2023년 10월 11일
편집: Torsten 2023년 10월 11일
I don't understand what your code from above is good for to solve the original problem.
You have to apply it the opposite way to use it in your problem: Solve f(d2u) - y(1) = 0 for d2u. But I think it doesn't matter much whether you define f as the function above or if you directly use the integral representation.

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

제품

릴리스

R2022a

질문:

2023년 10월 11일

편집:

2023년 10월 11일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by