Plotting Solutions to the Heat Equation Through a Truncated Series Evaluation
4 views (last 30 days)
Show older comments
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).
0 Comments
Answers (1)
Yongjian Feng
on 3 Nov 2021
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 Comments
Yongjian Feng
on 3 Nov 2021
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.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!