COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### Geometric Progression display help needed

• Follow

```im calculating a geometric progression and need to know how to display is it ar0+ar1+ar2+...+arn
this is the code i have:

x=5;
syms x
for i=1:19
x=x+5*(1/2)^i
end

but i want the display to show 5+5/2+15/4 and so on, i just need to know how to display it in this kind of format.
```
 0

```"Kevin " <kevin_stanza@yahoo.co.uk> wrote in message
news:hoagr3\$l5h\$1@fred.mathworks.com...
> im calculating a geometric progression and need to know how to display is
> it ar0+ar1+ar2+...+arn
> this is the code i have:
>
> x=5;
> syms x

This just overwrote the value of x that you assigned previously.  If you
really want x to be the symbolic value 5:

x = sym(5);

> for i=1:19
>    x=x+5*(1/2)^i
> end
>
> but i want the display to show 5+5/2+15/4 and so on, i just need to know
> how to display it in this kind of format.

FPRINTF.

x = sym(5);
two = sym(2);
fprintf('5');
for k = 1:19
end
fprintf('\n');

Note that x will not contain the individual terms; it will instead contain
the sum of the terms.  If you want to store the individual terms, create a
sym array and store each term in an element, then sum them up after the loop
is finished.

--
Steve Lord
slord@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ

```
 0

1 Replies
587 Views

Similiar Articles:

7/23/2012 3:57:57 PM