views:

130

answers:

3

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 print 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  A: 

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')
Rasmus Kaj
actually i want to display pi as symbol may be like this : 2 sin\pixbut wat function should i use? disp, title or text?
izzat
@izzat: How to do that depends on where you want to display it. `disp` writes to your matlab shell, and I don't think you can use tex there, but if your environment supports unicode, try simply `disp('2 sin πx')`. If you want it somewhere in a diagram, try `text` or `title` as described by MR-123.
Rasmus Kaj
A: 

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?

S.C. Madsen
i've tried with x=[11^2:2:111^2]sum(x)it gives different answer as yours...which one is correct?
izzat
@izzat [11:2:111] .^ 2 gives the squer of every other number from 11 to 111. [11^2:2:111^2] on the other hand, gives every other number from 121 to 12321.
Rasmus Kaj
Madsen's is correct. What your code does is actually x = [121:2:12321]; sum(x); <br> Which is not at all what you want. Those parens matter.
Marc
+3  A: 

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/

merv
Actually, pi does not exist in ASCII or ISO-8859-1. But it is U+03C0 in Unicode.
Rasmus Kaj
oops, my bad :)
merv

related questions