In examining ODE models containing parameters I don't like to assign values to these, but use the form

param:={a=2, b=7};
and then
eval(expression, param);

This works well. There are situations, however, where this method can be cumbersome.
This would be the case in a situation like this:

plot(a*sin(x),x=0..b);

You could do

plot(op(eval([a*sin(x),x=0..b],param)));

But maybe an operator having a syntax similar to 'assuming' could be useful.

The operator could be named 'assigning' and should make assignments, then execute the code and finally unassign.

Here is an attempt.

`&assigning`:=proc(x::uneval,par1::seq({equation,set(equation),list(equation)})) local par,res;
if par1=NULL then error "Most likely you forgot parentheses around your temporary assignments" end if;
par:=ListTools:-Flatten(evalindets([par1],set,rcurry(convert,list)));
assign(par);
try
  res:=eval(x);
catch:
  error;
finally  
  map(unassign@lhs,eval(par,2));
end try;
eval(res)
end proc:

plot(a*sin(x),x=0..b) &assigning param;
plot(a*sin(x),x=0..b) &assigning (a=-2,b=7);
plot(a*sin(x),x=0..b) &assigning ([a=-2],{b=Pi});
plot(a*sin(x),x=0..b) &assigning (a=-2,b=Pi);
#The following two will not work because of operator precedence
plot(a*sin(x),x=0..b) &assigning a=-2,b=Pi;
plot(a*sin(x),x=0..b) &assigning (a=-2),b=Pi;

 


Please Wait...