Simple problems with MATLAB
I have three questions:
1)
I want to compute the following using MATLAB:
11^2 + 13^2 + 15^2 + ... + 109^2 + 111^2
I have tried using:
x = [11^2 13^2 15^2 ... 109^2 111^2]
z = cum(single(x))
but I got an error...
2)
I want to display '2 sin/pix'... I tried:
tittle('2 sin/pix')
Can I represent the display without displaying it in figure?
3)
The Fibonacci series is given as follow:
1, 2, 3, 5, 8, 13, 21, ...
How can I write a script file to calculate and p开发者_Python百科rint out the n-th Fibonacci term for n>2, where n is input by the user.
This is what I've tried:
input('n: ')
z = cumsum(n)
fprintf('the series=%d')
but I received an error...
1)
sum([11:2:111].^2)
2) Depending on whether you want a title or a text in a figure:
text(.5,.5,'2 sin\pix', 'interpreter','tex')
title('2 sin\pix', 'interpreter','tex')
BTW, the ASCII symbol of π is: 227 (Press and hold ALT and type 227 on Windows)
3) Take a look at this page: http://blogs.mathworks.com/loren/2006/05/17/fibonacci-and-filter/
In the first subquestion, maybe you just mean sum
instead of cum
?
I would do it like this:
x = [11:2:111]
sum(x .^ 2)
The first line is a range, giving a vector of every other number from 11 to 111, the second does a per-element squaring in that vector and sums it.
For the second question, I'm not sure what you really want to do. How about:
disp('2 sin/pix')
To compute: 11^2+13^2+...+109^2+111^2, try: sum((11:2:111).^2)
To display '2 sin/pix'), the command is 'title' not 'tittle': title('2 sin/pix')
Is this homework?
精彩评论