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

In summary, MATLAB is supposed to show the list of independent variable 'n' and then another column showing the terms when n=0...10, but it is not displaying all the terms I need. Some of the outputs are in variable form and others in numerical form.
  • #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: 326
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: 576
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: 273
  • #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: 703
  • 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

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

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

To show the first 10 terms of a series in Matlab, you can use the "for" loop with a counter variable to iterate through the first 10 terms and print them out. Alternatively, you can use the "head" function to display the first 10 terms of a series.

2. Can I specify the starting term of the series when using the "for" loop?

Yes, you can specify the starting term of the series by setting the initial value of the counter variable in the "for" loop. For example, if you want to start at the 5th term, you can set the counter variable to 5.

3. How do I format the output to display the terms in a specific way?

In Matlab, you can use the "fprintf" function to format the output of the series. This function allows you to specify the formatting of the output, such as the number of decimal places or the use of scientific notation.

4. Is there a way to store the first 10 terms of a series in an array?

Yes, you can use the "for" loop to iterate through the first 10 terms and store them in an array. Alternatively, you can use the "head" function to create an array containing the first 10 terms of the series.

5. Can I display the series in a graphical form?

Yes, you can plot the first 10 terms of a series using the "plot" function in Matlab. You can also customize the plot by specifying the line style, color, and other properties. Alternatively, you can use the "stem" function to create a stem plot of the series.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
4
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
774
  • MATLAB, Maple, Mathematica, LaTeX
Replies
5
Views
2K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
2
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
3
Views
3K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
10
Views
1K
Back
Top