R: Plots come out blank except for certain limits
- To: mathgroup at smc.vnet.net
- Subject: [mg123659] R: Plots come out blank except for certain limits
- From: "Sir Bob Kinght" <sir.bob.knight at gmail.com>
- Date: Thu, 15 Dec 2011 04:51:37 -0500 (EST)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- References: <201112131041.FAA25312@smc.vnet.net>
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 at gmail.com] Inviato: marted=EC 13 dicembre 2011 11:42 A: mathgroup at 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
- References:
- Plots come out blank except for certain limits
- From: John Colvin <john.loughran.colvin@gmail.com>
- Plots come out blank except for certain limits