How can I plot this complex summation to infinity ?
Show older comments
Hi everyone,
I'm new to Matlab but am trying to plot a curve in accordance with the following equation:

Where E_n and D_n are solved as follows:


If someone was able to suggest how I might go about achieving this, or point me in the direction of a good resource so I may learn, that would be brilliant. Thank you!
Answers (1)
Star Strider
on 25 Jul 2019
You can’t.
Use meshgrid or ndgrid to calculate the ‘x’ and ‘t’ matrices. (You will have to have them as matrices for your function to work.)
You don’t need to do an infinite sum. Instead, use a while loop to stop when the value of ‘T(x,t)’ is no longer changing between iterations.
Example (sine series):
x = pi/9;
n = 0;
S = 0;
Sp = Inf;
err = 1;
while err > 1E-8
S = S + ((-1)^n)/factorial(2*n+1) * x^(2*n+1)
err = abs(S - Sp);
Sp = S;
n = n + 1;
end
That produces a decent approximation, and converges in a few iterations (depending on the threshold set for ‘err’). Since your function will return a matrix, you will have to write your loop to recognise that, and calculate ‘err’ (in this example, call it what you like in your code) correctly.
8 Comments
Tom Coates
on 25 Jul 2019
Star Strider
on 25 Jul 2019
My pleasure.
My Answer simply illustrates how to use a while loop to converge on an appropriate result without going beyond a reasonable iteration limit.
You can easily evaluate your function. You cannot sum it to infinity, first because at some point the calculation would no longer add any precision to the result (the reason for the while loop), and second because an infinite summation would literally take forever.
You first need to code it (most likely in a function file) using appropriate values for the constants (B, C, and L), then use a while loop to do the finite summation.
Use meshgrid or ndgrid to create matrices from the ‘x’ and ‘t’ vectors, since they need to both be the same sized matrices in all the calculations. You can either pass them to your function as matrices, or pass them to your function as vectors, then create the matrices within the function file.
So code the expressions. If you have problems getting your code to run, post back here with specific dsecriptions of any problems you have, and if your code throws errors, copy and paste all the red text from your Command Window to a Comment requesting help with your code. It also helps to include representative values for ‘x’ and ‘t’. If you know the values your function should return for ‘T(x,t)’, posting those (or a link to them) would also be helpful.
Tom Coates
on 25 Jul 2019
Edited: Tom Coates
on 25 Jul 2019
Star Strider
on 25 Jul 2019
My pleasure.
If you got your expression from a reputable source, that Excel is returning the wrong results simply means that Excel is returning the wrong results, for whatever reason. (I have not coded anything in Excel in decades.) Coding it in MATLAB would likely return the correct results.
If you need an introduction to MATLAB see Getting Started. I will do my best to help if you have problems.
Tom Coates
on 25 Jul 2019
Star Strider
on 25 Jul 2019
My pleasure!
If that’s the correct solution to your PDE, you should have no problems coding it. The MATLAB Symbolic Math Toolbox isn’t set up to solve PDEs, however if your PDE is relatively simple, linear, and separable, a symbolic solution is possible with it. You can then easily export that solution as a function that MATLAB can solve numerically. (I haven’t done anything with PDEs in a very long time. There may be online solvers that can integrate it for you if the Symbolic Math Toolbox cannot.)
Star Strider
on 25 Jul 2019
Tom Coates’s Answer moved here —
I didn’t realise such a program existed, I’ve been trying to solve it analytically myself. I’ll check that out, thanks :)
Star Strider
on 25 Jul 2019
My pleasure.
Examples —
How To Solve a Partial Differential Equation (Wolfram Alpha)
That is the only online symbolic solver I can find. I don’t know if Maple has that capability.
A MATLAB numeric approach: Partial Differential Equations as well as the Partial Differential Equation Toolbox, although none give symbolic solutions. Again, if yur PDE is amenable to using Laplace transforms, the Symbolic Math Toolbox can do that (although you will need to help it along if you use Laplace transforms).
Categories
Find more on Eigenvalue Problems in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!