Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #7216

R: Plots come out blank except for certain limits

From "Sir Bob Kinght" <sir.bob.knight@gmail.com>
Newsgroups comp.soft-sys.math.mathematica
Subject R: Plots come out blank except for certain limits
Date 2011-12-15 09:53 +0000
Organization Steven M. Christensen and Associates, Inc and MathTensor, Inc.
Message-ID <jccg2a$mad$1@smc.vnet.net> (permalink)
References <201112131041.FAA25312@smc.vnet.net>

Show all headers | View raw


Hi John,
the problem is the assignment of the function f[a, b]. Indeed, the right
code is:

f[a_, b_] = Integrate[.......]

the difference is the use of symbol _ for each input parameter, that is a_
instead of a and b_ instead of b.

Try with a smaller example to better understand the meaning of such
terminology.

Define a function like the following

In[10]:= g[a, b] = a Cos[x] + b Sin[x]
Out[10]= a Cos[x] + b Sin[x]

And see its definition

In[11]:= ?? g

Global`g
g[a,b]=a Cos[x]+b Sin[x]

it means that g will come into force only when called with the two symbols a
and b literally. No other inputs will trigger the evaluation of the right
hand side of your definition.
Try
In[12]:= g[1, 1]
Out[12]= g[1, 1]

This is right because 1 is neither a or b.

On the other hand, if you define

g[a_, b_] = <something>

it means that g will accept "any input" as first and second argument and
"then" will assign the name a and b to them in order to evaluate the right
hand side of the definition.

Take a look at the following docs in the Mathematica Documentation Center

tutorial/DefiningFunctions
tutorial/ImmediateAndDelayedDefinitions

hope this helps,
~roberto


-----Messaggio originale-----
Da: John Colvin [mailto:john.loughran.colvin@gmail.com]
Inviato: marted=EC 13 dicembre 2011 11:42
A: mathgroup@smc.vnet.net
Oggetto: Plots come out blank except for certain limits

Hi, I'm an absolute beginner with Mathematica so I may well have missed
something very simple.
I'm trying to visualise a simple minimisation problem in 2 parameters

This is the code i run:
f[a, b] = Integrate[(Sin[5*x] + Sin[3*x] - Sin[a*x] - Sin[b*x])^2, {x, 0,
10}] this takes quite a while and returns a VERY long result

then I attempt to plot:
Plot3D[f[a, b], {a, 0, 10}, {b, 0, 10}]

the resulting plot is a 3D sinusoidal of sorts, from f = -1..1. Unless I'm
very much mistaken, the integral of the square of a real-valued function
should always be positive, so something seems amiss here already.

Also, if I change the a and b ranges:
Plot3D[f[a, b], {a, 0, 12}, {b, 0, 12}]
for example, I get a blank plot

I realise I may just be missing something simple, but any help would be much
appreciated.

Thanks,
John

Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread


Thread

R: Plots come out blank except for certain limits "Sir Bob Kinght" <sir.bob.knight@gmail.com> - 2011-12-15 09:53 +0000

csiph-web