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

52 views (last 30 days)
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;

Accepted Answer

Bruno Luong
Bruno Luong on 16 Aug 2020
Edited: Bruno Luong on 16 Aug 2020
"(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

More Answers (2)

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

Sign in to comment.


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

Products

Community Treasure Hunt

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

Start Hunting!