Graphing a function for several parameter values



Je la 13/02/2012 18:10, Patrick Blanchenay skribis:
> Je la 13/02/2012 17:53, Patrick Blanchenay skribis:
>> Je la 13/02/2012 17:02, Jaime Villate skribis:
>>> On 02/13/2012 04:20 PM, Patrick Blanchenay wrote:
>>>> Do you know if I could apply the substitution of parameters to several
>>>> functions?
>>>>
>>>> E.g. something like:
>>>>
>>>> flist: makelist ( concat(ev(f(x,p1,p2), p),",",ev(g(x,p1,p2), p)), p,
>>>> plist);
>>>> plot2d ( flist, [x, 0, 7]);
>>>>
>>>> I have no idea, but basically i'd like to plot two functions for several
>>>> parameters values, so I need to have them like
>>>> [f(under param_set1), g(under param_set1), f(under param_set2), g(under
>>>> param_set2)]
>>>>
>>>> Is this still feasible with makelist?
>>> Sure, something such as:
>>>
>>> flist: makelist ( ev( [f(x,p1,p2), g(x,p1,p2)], p), p, plist)$
>>> plot2d (flatten (flist), [x, 0, 7]);
>>>
>>> That makelist command will create a list of the type [[f1,g1], [f2,g2],...]
>>> flatten() will transform it into the list that plot2d needs: [f1, g1,
>>> f2, g2, ...]
>>>
>>
>> Ah, flatten is exactly what I needed. Thank you very much for your help!
>> (And thank you Alexander as well!)
> 
> Actually I spoke too fast, the problem is that my functions are
> parametric, so each of them need to be in ['parametric,
> xOne(t),yOne(t),[t,0,1]]. In other words, not everything should be
> flatten. Is there any way to get "intermediate" flattening?
> 
> What I get from the makelist() command, with for instance:
> 	plist: [ [p1=1, p2=2], [p1=3, p2=4] ]
> is:
> [
> 	[
> 		['parametric, xOne(t,1,2),yOne(t,1,2),[t,0,1]],
> 		['parametric, xTwo(t,1,2),yTwo(t,1,2),[t,0,1]]
> 	],
> 	[
> 		['parametric, xOne(t,3,4),yOne(t,3,4),[t,0,1]],
> 		['parametric, xTwo(t,3,4),yTwo(t,3,4),[t,0,1]]
> 	]
> ]
> 
> What I would like is to suppress the "intermediate" level of hierarchy,
> in order to get:
> [
> 	['parametric, xOne(t,1,2),yOne(t,1,2),[t,0,1]],
> 	['parametric, xTwo(t,1,2),yTwo(t,1,2),[t,0,1]],
> 	['parametric, xOne(t,3,4),yOne(t,3,4),[t,0,1]],
> 	['parametric, xTwo(t,3,4),yTwo(t,3,4),[t,0,1]]
> ]
> 
> whereas if I use flatten, I get:
> ['parametric, xOne(t,1,2),yOne(t,1,2),t,0,1,
> 'parametric, xTwo(t,1,2),yTwo(t,1,2),t,0,1,
> 'parametric, xOne(t,3,4),yOne(t,3,4),t,0,1,
> 'parametric, xTwo(t,3,4),yTwo(t,3,4),t,0,1]
> 
> Any suggestions?

I found how to do it using "append":

	f(x,A,w):= A*sin(w*x)$
	g(x,B,w):= B*cos(w*x)$
	parameterList: [ [p1=1, p2=2], [p1=3, p2=4] ]$
	functionList:
		apply(append,
			makelist(
				ev(
				[['parametric, 2*t, f(t,p1,p2),
					[t, 0, 1], [nticks, 300]],
				['parametric, g(t,p1,p2), 5*t+2,
					[t, 0, 1], [nticks, 300]]],
				p),
			p, paramaterList)
		);
	plot2d(functionList, [x, 0, 7]);

Sorry about the spam!