On Fri, 26 Feb 2010, Janek Kozicki wrote:
< ok, I managed to do what I wanted here. It plots lines tangent to an ellipse!
<
< Please have a look at my first wxmaxima script :)
<
< Last question - is it possible to make the last step shorter and more readable?
< The one, where I declare A_RES,EL,LINE_1,LINE_2.
I think that some programming styles require one to store intermediate
results in variables, and to handle list/array variables by accessing
the elements individually. I think Maxima style is more compact:
feel free to use multiple commands in one line, and use built-in
functions to iterate over lists where possible.
Here is how I would write the last bit of your script:
/* since these parameters define your problem, define them in 1 line */
(a:5,b:3,B:1,x0:7,y0:-8);
...
ellipse_parametric:[[parametric,a*cos(t),b*sin(t),[t,0,2*%pi]]];
lines:flatten(map(lambda([t],subst(A=t,map(rhs,''line_y))),map(rhs,''A_res)));
plot2d(append(lines,ellipse_parametric),
[x,-20,20],
[y,-10,10],
[nticks,200],
[grid,20,10],
[axes, 'x],
[legend,"ellipse","tangent","tangent"]);
I don't know if you consider this more readable at this point, but an
advantage is that I don't need to know how many solutions in A_res there
are, nor how many solutions in line_y there are, my definition of
'lines' will work and so therefore will the plot2d command.
Leo
--
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.