필터 지우기
필터 지우기

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

조회 수: 18 (최근 30일)
esat gulhan
esat gulhan 2020년 8월 16일
답변: krishnil 2023년 4월 24일
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
KSSV
KSSV 2020년 8월 16일
y = deval(sol,t,1))
What is size of y?
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