How can i find the dy/dx of the differantial equation

18 次查看(过去 30 天)
My differantial equation is 1/x*d/dx(x*dy/dx)=10.
And my code is below. I can solve x, y but i can not solve dy/dx, how to find dy/dx value of this problem. (My Code is correct)
function SteadyHeat1DNumeric
clc; clear;
x1=0.06; x2=0.08;
t=linspace(x1,x2,21);
tspan = [x1 x2];
xmesh = linspace(x1,x2);solinit = bvpinit(xmesh, @guess);sol= bvp5c( @heatcylinder1D, @bcfcn, solinit);
for t=linspace(x1,x2,11)
fprintf('%12.5f',t,deval(sol,t,1));fprintf('\n')
end
function res = bcfcn(ya,yb)
global h k Ts q
res = [ya(1)-150
yb(1)-60];
function g = guess(x)
g = [1 1000];
function dxdy = heatcylinder1D(x,y)
global g k
dxdy = zeros(2,1);
dxdy(1) = y(2)/x;
dxdy(2) = 10;

采纳的回答

Bruno Luong
Bruno Luong 2020-8-16
编辑:Bruno Luong 2020-8-16
"(My Code is correct)"
To me it's not. See below for the correction (the problem is I can't see it's change the solution after fixing the code, and I don't know why and did not investigated further for reason).
I give you here the code corrected + 2 methods to computs dy/dx
x1=0.06; x2=0.08;
xmesh = linspace(x1,x2);
solinit = bvpinit(xmesh, @guess);
sol= bvp5c( @heatcylinder1D, @bcfcn, solinit);
figure
hold on
plot(gradient(sol.y(1,:),sol.x),'ro-')
plot(deval(sol,sol.x,2)./sol.x,'b+-')
legend('dy/dx gradient','dy/dx deval')
function res = bcfcn(ya,yb)
res = [ya(1)-150
yb(1)-60];
end
function g = guess(x)
g = [1 1000];
end
function dxdy = heatcylinder1D(x,y)
dxdy = zeros(2,1);
dxdy(1) = y(2)/x;
dxdy(2) = 10*x; % <= error is here
end

更多回答(2 个)

KSSV
KSSV 2020-8-16
You can use gradient function.
dy = gradient(y) ;
dx = gradient(x) ;
dydx = dy./dx ; % dy/dx
  5 个评论
esat gulhan
esat gulhan 2020-8-16
Oh size is 2. I think i find the solution. deval(sol,t,2),
thanks

请先登录,再进行评论。


krishnil
krishnil 2023-4-24
Compute∇·Fand∇×F. 1.
F(x,y,z)=x2i−2j+yzk.

类别

Help CenterFile Exchange 中查找有关 Ordinary Differential Equations 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by