Plotting Solutions to the Heat Equation Through a Truncated Series Evaluation

2 次查看(过去 30 天)
I have a solution to the heat equation (a function of two variables $x$ and $t$) which is in the form of an infinite series. I want to know what the solution actually looks like at specific times. My solution is:
where the coefficients are given by
and
and the function is known and given at the bottom. I am having problems with my Matlab code when I try to actually calculate these things however. What I have right now is:
h = .01;
xVec = 0:h:5;
for n = 1:100
h_FC_integrand = @(x,s) (x.*(10-x).*sin((pi*n.*x)/5) ./ (1+ ...
(x-5 * (1 + sin(2*pi.*s)./(s+1))).^2));
h_FC = @(s) ((2/5) * exp(((n*pi)/5)^2 * s) * ...
quadgk(h_FC_integrand,x,0,5));
Cn = quadgk(h_FC,0,.01);
sinVec = sin((pi*n*xVec)/5);
solutionVec1 = solutionVec1 + (Cn * exp(-((n*pi)/5)^2 * .01) ...
.*sinVec);
end
The problem is in the line where I try to evaluate for . Matlab is giving me the error "Not enough input arguments." but I don't see what the problem is. The function handle h_FC is of only one variable so I don't need to specify which variable I want to integrate in and I give both the endpoints of integration. Any help would be much appreciated!
For reference:
Also, this same basic idea worked quite easily when the coefficients had no time dependence (I tried essentially this exact same method for a different problem and had no issues).

回答(1 个)

Yongjian Feng
Yongjian Feng 2021-11-3
The error seems to be caused by this line:
quadgk(h_FC_integrand,x,0,5));
quadgk computes numerical integration. What do you expect from this please?
  4 个评论
Mark Fasano
Mark Fasano 2021-11-3
This significantly slowed my code. Changing h to be .1 and lowering n to only range from 1 to 10 now takes a lot of time but I don't really see why. Any insights? Ideally I'd want my space discretization to stay the same so the plot remains smooth
Yongjian Feng
Yongjian Feng 2021-11-3
If you are doing symbolic integration of h_FC_integrand, maybe you can take it out of the for loop? So it becomes a function of t and n, instead of a funciton of t. Then inside the for loop, you can substitute n.
It seems to be the int function can be called outside the for loop.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Logical 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by