# Solution of a second order differential equation

2 views (last 30 days)
Swami on 31 Jan 2024
Commented: Sam Chak on 31 Jan 2024
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

Sam Chak on 31 Jan 2024
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 CommentsShow NoneHide None
Swami on 31 Jan 2024
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 on 31 Jan 2024
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!

### Categories

Find more on Boundary Value Problems in Help Center and File Exchange

R2022a

### Community Treasure Hunt

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

Start Hunting!