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

57 ビュー (過去 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
  1 件のコメント
esat gulhan
esat gulhan 2020 年 8 月 16 日
Pretty answer, thank you

サインインしてコメントする。

その他の回答 (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 Center および File ExchangeOrdinary Differential Equations についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by