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

AI Thread Summary
The discussion revolves around using MATLAB to display a list of independent variable 'n' alongside corresponding terms for values from 0 to 10. The user initially struggles with displaying the desired output correctly, particularly with the symbolic representation of terms. A mentor suggests a revised approach using the command "S = 1 ./ z.^(n-1)" to ensure proper output formatting. The user learns that the periods in the command indicate element-wise operations, which is crucial for matrix calculations. For improved readability of the output, the command "pretty(S)" is recommended, and if further formatting is needed, the output can be converted to LaTeX using "latex(S)" for better presentation. The discussion also notes potential issues with the MATLAB Android app regarding command execution history, emphasizing a smoother experience on the desktop version.
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: 646
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: 335
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: 766
  • 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
Views
3K
Replies
4
Views
1K
Replies
2
Views
2K
Replies
5
Views
2K
Replies
1
Views
2K
Replies
4
Views
2K
Back
Top