How do I get Matlab to show the first 10 terms of a series?

  • #1
majormuss
124
4
I have attached a picture of what I want Matlab to do. I basically want Matlab to show the list of independent variable 'n' and then another column showing the terms when n=0...10. Some of the outputs are in variable form and others in numerical form.
My attempt so far is stated below. I have no idea why it is not displaying all the terms I need. Any ideas?
Matlab:
>> n=0:10;
>> syms z n
>> S = 1/z^(n-1)

S =

z^(1 - n)

>> T = table(n,S,0:10)

T =

  1×3 table

        n            S            Var3   
    _________    _________    _____________

    [1x1 sym]    [1x1 sym]    [1x11 double]

>>

<< Mentor Note -- code tags added >>
 

Attachments

  • Matlab support .pdf
    54.4 KB · Views: 365
Last edited by a moderator:
Physics news on Phys.org
  • #2
Just do it this way (don't copy and paste, as that often gives an error):
Matlab:
syms z;
n = 0:10;
S = 1 ./ z.^(n-1);
S

Output:
Screenshot_20190117-222019.png

Edit: fixed image.
 

Attachments

  • Screenshot_20190117-222019.png
    Screenshot_20190117-222019.png
    5.3 KB · Views: 608
Last edited:
  • Like
Likes majormuss
  • #3
Wrichik Basu said:
Just do it this way (don't copy and paste, as that often gives an error):
Matlab:
syms z;
n = 0:10;
S = 1 ./ z.^(n-1);
S

Output:
https://www.physicsforums.com/attachments/237445
Awesome. Thanks. What do the periods mean?
 
  • #4
majormuss said:
Awesome. Thanks. What do the periods mean?
Nevermind. I got it. Looked it up here Thanks again!
 
  • Like
Likes Wrichik Basu
  • #5
Wrichik Basu said:
Just do it this way (don't copy and paste, as that often gives an error):
Matlab:
syms z;
n = 0:10;
S = 1 ./ z.^(n-1);
S

Output:
https://www.physicsforums.com/attachments/237445
Quick follow up question: Is there a way to make MATLAB display the output in a more readable format like the way like in the attached picture?
 

Attachments

  • example.jpg
    example.jpg
    6.6 KB · Views: 305
  • #6
majormuss said:
Quick follow up question: Is there a way to make MATLAB display the output in a more readable format like the way like in the attached picture?
The left side cannot be shown like that. This is because ##S## is a Matrix, and matrix values are not printed like that.

You can, however, use a command:
Matlab:
pretty(S)
This is supposed to show the output in a better format.

Often, you will find that you have got some output that is not looking good using the above command. You can then take out the whole thing into LaTeX with the following command:
Matlab:
latex(S)
Now copy everything the function returns, and use a LaTeX viewer like QuickLatex for the best results.

Matlab android app has some problems (I believe) copying previously executed commands or their returns. But you won't have a problem working on the desktop version.

The output screen is below:

Screenshot_20190117-234628.png
 

Attachments

  • Screenshot_20190117-234628.png
    Screenshot_20190117-234628.png
    11.7 KB · Views: 738
  • Like
Likes majormuss
  • #7
Wrichik Basu said:
The left side cannot be shown like that. This is because ##S## is a Matrix, and matrix values are not printed like that.

You can, however, use a command:
Matlab:
pretty(S)
This is supposed to show the output in a better format.

Often, you will find that you have got some output that is not looking good using the above command. You can then take out the whole thing into LaTeX with the following command:
Matlab:
latex(S)
Now copy everything the function returns, and use a LaTeX viewer like QuickLatex for the best results.

Matlab android app has some problems (I believe) copying previously executed commands or their returns. But you won't have a problem working on the desktop version.

The output screen is below:

View attachment 237454
Wrichik Basu said:
The left side cannot be shown like that. This is because ##S## is a Matrix, and matrix values are not printed like that.

You can, however, use a command:
Matlab:
pretty(S)
This is supposed to show the output in a better format.

Often, you will find that you have got some output that is not looking good using the above command. You can then take out the whole thing into LaTeX with the following command:
Matlab:
latex(S)
Now copy everything the function returns, and use a LaTeX viewer like QuickLatex for the best results.

Matlab android app has some problems (I believe) copying previously executed commands or their returns. But you won't have a problem working on the desktop version.

The output screen is below:

View attachment 237454
Perfect! Thanks a lot!
 
  • Like
Likes Wrichik Basu

Similar threads

Replies
4
Views
3K
Replies
4
Views
297
Replies
2
Views
2K
Replies
5
Views
2K
Replies
1
Views
2K
Replies
3
Views
4K
Back
Top