Solution of a second order differential equation

조회 수: 2 (최근 30일)
Swami
Swami 2024년 1월 31일
댓글: Sam Chak 2024년 1월 31일
I am unable to solve a differential equation using dsove command in Matlab. I get the Warning: Unable to find symbolic solution. Can you please help me with it.
clc
clear
close
syms y(x)
L=1;
A=1;
p=x^2;
s=10*diff(y,x)+100000*(diff(y,x))^3;
DE = diff(s*A,x,1)+p;
cond = [y(0.0)==0.0, y(L)==1.0];
sol = dsolve(DE==0.0,cond)
Warning: Unable to find symbolic solution.
sol = [ empty sym ]
Also I tried using bvp4c to solve it but was still unsuccessful. I have enclosed the code below. Thanks a lot for your help
!
clc
clear
close
L=1;
A=1;
% Using bvp4c
x=linspace(0,L,12);
yi=bvpinit(x,[1,1])
yi = struct with fields:
solver: 'bvpinit' x: [0 0.0909 0.1818 0.2727 0.3636 0.4545 0.5455 0.6364 0.7273 0.8182 0.9091 1] y: [2×12 double] yinit: [1 1]
sol=bvp4c(@bvpfcn,@bcfcn,yi)
Not enough input arguments.

Error in solution>bvpfcn (line 26)
-x^2/(10*A+300000*(y(2))^2)];

Error in bvparguments (line 96)
testODE = ode(x1,y1,odeExtras{:});

Error in bvp4c (line 119)
bvparguments(solver_name,ode,bc,solinit,options,varargin);
function dydx = bvpfcn(x,y,A)
dydx = zeros(2,1);
dydx = [y(2)
-x^2/(10*A+300000*(y(2))^2)];
end
function res = bcfcn(ya,yb)
res = [ya(1)-0.0
yb(1)-1.0];
end

답변 (1개)

Sam Chak
Sam Chak 2024년 1월 31일
I've got a solution from the bvp4c() solver.
syms y(x)
L = 1;
A = 1;
p = x^2;
s = 10*diff(y,x) + 100000*(diff(y,x))^3
s(x) = 
DE = diff(s*A,x,1) + p == 0;
[V, S] = odeToVectorField(DE)
V = 
S = 
clear
L = 1;
%% Using bvp4c
x = linspace(0, L, 21);
yi = bvpinit(x, [1, 1]);
sol = bvp4c(@bvpfcn, @bcfcn, yi);
x = sol.x;
y = sol.y;
%% Plot results
plot(x, y, '-o', 'linewidth', 1), grid
xlabel('x', 'fontsize', 14)
ylabel('y', 'fontweight', 'bold', 'fontsize', 14)
legend('y_{1}', 'y_{2}', 'location', 'southeast')
%% Differential equations
function dydx = bvpfcn(x,y)
A = 1;
dydx = [y(2);
- (x^2)/(300000*y(2)^2 + 10*A)];
end
%% Boundary condition
function res = bcfcn(ya,yb)
res = [ya(1) - 0;
yb(1) - 1];
end
  댓글 수: 2
Swami
Swami 2024년 1월 31일
Thank you very much for the solution. But what changes did you make here? The code looks the same as before.
Best,
Swami
Sam Chak
Sam Chak 2024년 1월 31일
I'm glad it works. What I did, I moved 'A = 1' to the bvpfcn() function so that I don't need to call unnecessary extra parameters. I like to place constants inside the function unless I want to test out some parameters. Generally, your bvp4c code works if you make a change to this line using this syntax to call 'A'.
sol = bvp4c(@(x, y) bvpfcn(x, y, A), @bcfcn, yi)
If you find the solution helpful, please consider clicking 'Accept' ✔ on the answer and voting 👍 for it. Thanks a bunch!

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

카테고리

Help CenterFile Exchange에서 Boundary Value Problems에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by