Solution of a second order differential equation
2 次查看(过去 30 天)
显示 更早的评论
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)
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])
sol=bvp4c(@bvpfcn,@bcfcn,yi)
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
0 个评论
回答(1 个)
Sam Chak
2024-1-31
Hi @Swami
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
DE = diff(s*A,x,1) + p == 0;
[V, S] = odeToVectorField(DE)
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 个评论
Sam Chak
2024-1-31
Hi @Swami
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 Center 和 File Exchange 中查找有关 Boundary Value Problems 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!