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

  • Context: MATLAB 
  • Thread starter Thread starter majormuss
  • Start date Start date
  • Tags Tags
    Matlab Series Terms
Click For Summary

Discussion Overview

The discussion revolves around how to use MATLAB to display the first 10 terms of a series, focusing on the output format and handling symbolic variables. Participants share their attempts, solutions, and questions regarding the display of results.

Discussion Character

  • Technical explanation
  • Homework-related
  • Debate/contested

Main Points Raised

  • One participant shares their initial attempt to display terms of a series in MATLAB but encounters issues with the output format.
  • Another participant suggests a corrected approach using element-wise operations with the syntax "1 ./ z.^(n-1)" to generate the series terms.
  • There is a question about the meaning of the periods in the suggested MATLAB code, which is later resolved by the same participant.
  • A follow-up question is raised about making the output more readable, leading to suggestions for using the "pretty(S)" and "latex(S)" commands to improve formatting.
  • Participants discuss the limitations of displaying matrix values in MATLAB and the challenges faced when using the MATLAB Android app compared to the desktop version.

Areas of Agreement / Disagreement

Participants generally agree on the methods to display the series terms but express differing views on the output formatting and the limitations of MATLAB's display capabilities.

Contextual Notes

Some limitations are noted regarding the display of matrix values and the functionality of the MATLAB Android app, which may affect how outputs are copied or displayed.

majormuss
Messages
124
Reaction score
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

Last edited by a moderator:
Physics news on Phys.org
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: 690
Last edited:
  • Like
Likes   Reactions: majormuss
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?
 
majormuss said:
Awesome. Thanks. What do the periods mean?
Nevermind. I got it. Looked it up here Thanks again!
 
  • Like
Likes   Reactions: Wrichik Basu
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: 359
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: 809
  • Like
Likes   Reactions: majormuss
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   Reactions: Wrichik Basu

Similar threads

  • · Replies 4 ·
Replies
4
Views
4K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 5 ·
Replies
5
Views
4K
  • · Replies 3 ·
Replies
3
Views
5K
Replies
2
Views
3K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K