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

Click For Summary
SUMMARY

This discussion focuses on generating and displaying the first 10 terms of a series in MATLAB using symbolic variables. The user initially attempted to create a table with independent variable 'n' and the corresponding terms using the command S = 1/z^(n-1), which resulted in an incorrect output format. The mentor provided a corrected approach using S = 1 ./ z.^(n-1) to ensure proper element-wise operations. Additionally, the use of pretty(S) and latex(S) commands was recommended for better output formatting.

PREREQUISITES
  • Understanding of MATLAB syntax and commands
  • Familiarity with symbolic mathematics in MATLAB
  • Knowledge of matrix operations in MATLAB
  • Basic understanding of LaTeX for formatting outputs
NEXT STEPS
  • Learn how to use MATLAB's pretty function for improved output formatting
  • Explore MATLAB's symbolic toolbox for advanced mathematical computations
  • Investigate the use of LaTeX in MATLAB for professional document preparation
  • Understand element-wise operations in MATLAB to avoid common syntax errors
USEFUL FOR

MATLAB users, students in engineering and mathematics, and anyone looking to enhance their skills in symbolic computation and output formatting in MATLAB.

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: 671
Last edited:
  • Like
Likes 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 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: 345
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: 791
  • Like
Likes 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 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
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 3 ·
Replies
3
Views
5K
Replies
2
Views
3K
  • · Replies 12 ·
Replies
12
Views
3K
  • · Replies 4 ·
Replies
4
Views
2K