How can I plot this complex summation to infinity ?

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)

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

Thank you for your response, unfortunately being new to matlab, I can't really make sense of your answer. Sounds like theres no simple way to evaluate this function then unfortunately.
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.
That’s great, thank you. That gives me a place to get started :)
I do have the values my function should return. Unfortunately I’ve tried to run my function in excel and it seems to converge upon the incorrect value of T. So my equation presented here may well be incorrect.
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.
In that case, I’ll try my best to generate a solution in MatLab also. From what I can tell excel isn’t the problem, but hopefully you’re right and I don’t need to resolve my partial differential equation. Thank you again :)
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.)
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 :)
My pleasure.
Examples —
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).

Sign in to comment.

Asked:

on 25 Jul 2019

Commented:

on 25 Jul 2019

Community Treasure Hunt

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

Start Hunting!