Group Abstract Group Abstract

Message Boards Message Boards

0
|
4.1K Views
|
5 Replies
|
0 Total Likes
View groups...
Share
Share this post:

How to generate good looking output?

Posted 11 years ago

Hey,

I've been trying to write my own program to calculate the Fourier-Coefficients and so far the program works but has an awful output.

I would like to have ai and bi written next to each output and also have the results for a and b in the same line, except a0 has to standalone or b0 has to be 0.

This is my code so far:

Clear[n, t, f, i, ak, bk] f[t_] := \[Pi]^2 - t^2; ak[f_, n_, t_] := (1/\[Pi]) Integrate[f[t] Cos[n t], {t, -\[Pi], \[Pi]}]; bk[f_, n_, t_] := (1/\[Pi]) Integrate[f[t] Sin[n t], {t, -\[Pi], \[Pi]}] n = 5; For[i = -1, i < n, Print[i.ak[f, i, t]], i++] For[i = 0, i < n, Print[i.bk[f, i, t]], i++]

Can someome help me and make the ouput more plesseant to look at. I have not done something like this in MATHEMATICA before.

Thanks for your help in advance and have a nice day.

POSTED BY: tt5 kk6
5 Replies

Well, you have to make up your mind as to which t to use for the accuracy. One way would be to maximize Abs[f[t]-fn[t]] over all t. You can use FindMaxValue.

POSTED BY: Gianluca Gorni
Posted 11 years ago

That is almost what i mean, but i meant the Approximation for each point. So what i wanted to do was to use:

el2distance[f_, fn_] := Abs[f[t] - fn[t]]]

But MATHEMATICA now gives me an errormessage saying:

Abs[0. +t$322115-2. Sin[t$322115]+1. Sin[2. t$322115]-0.666667 Sin[3. t$322115]+0.5 Sin[4. t$322115]-0.4 Sin[5. t$322115]] should be a real number or a list of non-negative numbers, which has the same length as {\!\(\*

I guess what i have to do is to numerically calculate the value of that expression? But how?

POSTED BY: tt5 kk6
POSTED BY: Gianluca Gorni
Posted 11 years ago
POSTED BY: tt5 kk6

Something like this?

TableForm[Table[{i, ak[f, i, t], bk[f, i, t]}, {i, -1, 10}], 
 TableHeadings -> {None, {k, ak, bk}}]

or else

Grid[Table[{i, ak[f, i, t], bk[f, i, t]}, {i, -1, 10}], Frame -> All]

Why do you make ak and bk depend on t, when they don't?

POSTED BY: Gianluca Gorni
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard