Group Abstract Group Abstract

Message Boards Message Boards

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

How to generate good looking output?

Posted 10 years ago
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 10 years ago
POSTED BY: tt5 kk6

My guess is that you had given t a numeric value, and this interfered with Integrate. You can protect the integration variable by wrapping it into Module:

Clear[ak, bk];
ak[f_, n_] := 
  ak[f, n] = 
   Module[{t}, (1/\[Pi]) Integrate[f[t] Cos[n t], {t, -\[Pi], \[Pi]}]];
bk[f_, n_] := 
  bk[f, n] = 
   Module[{t}, (1/\[Pi]) Integrate[f[t] Sin[n t], {t, -\[Pi], \[Pi]}]];
f[t_] := \[Pi]^2 - t^2;
ak[f, 2]

Also, it may be prudent to use NIntegrate instead of Integrate, unless you know in advance that your integrals have a closed form. As for the FillingStyle, you may first define your measure of accuracy, for example the L2 distance

el2distance[f_, fn_] := 
 Module[{t}, Sqrt@NIntegrate[Abs[f[t] - fn[t]]^2, {t, -Pi, Pi}]]

and then write something like

FillingStyle -> GrayLevel[el2distance[f, fn]]

This may not work straight away, because you probably have to normalize the distance first, as GrayLevel[x] wants x between 0 and 1. Instead of GrayLevel[x], you may prefer something like Blend[{Blue, Red}, x].

POSTED BY: Gianluca Gorni
Posted 10 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