How can i find the dy/dx of the differantial equation
57 ビュー (過去 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;
0 件のコメント
採用された回答
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
2020 年 8 月 16 日
You can use gradient function.
dy = gradient(y) ;
dx = gradient(x) ;
dydx = dy./dx ; % dy/dx
5 件のコメント
参考
カテゴリ
Help Center および File Exchange で Ordinary Differential Equations についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!