|
From: Stavros M. <mac...@gm...> - 2022-11-18 15:53:37
|
This is not a very good way to plot contours. The purely numerical approach
used by the plotting routines will work much better.
Here are some of the issues:
* Solve is designed to give exact solutions, so you will get solutions in
radicals, not floating-point numbers (even with float inputs and
*keepfloat:true*)
* You can silence the "rat replaced" messages by setting *ratprint:false*,
but those warnings are telling you that Maxima is calculating with
rationals rather than floats. e.g., *solve(x^2=.14,x) *gives the exact
solution *sqrt(7)/(5*sqrt(2)) *rather than 0.374
* At the very least, you should convert everything to numbers before any
further calculations (including *min*).
* It is almost always a bad idea to use *ev* in code. I think you can
replace *ev(...,numer)* with *float(...)*
* Your code isn't robust in the case of imaginary solutions.
But overall, I think you should depend on the plotting packages' contour
plotting capabilities as others have mentioned.
-s
On Thu, Nov 17, 2022 at 10:07 PM Eduardo Ochs <edu...@gm...> wrote:
> Hi list,
>
> a few days ago I had to draw some level curves of
>
> F(x,y) := 2*x^2 - x*y - y^2;
>
> in TikZ. I was in a hurry, so I wrote something that was an uglier
> version of this,
>
> F(x,y) := 2*x^2 - x*y - y^2;
> xs(y,z) := solve(F(x,y)=z, x);
> maxsol(sols) := apply('max, map('rhs, sols));
> minsol(sols) := apply('min, map('rhs, sols));
> leftx (y,z) := minsol(xs(y,z));
> rightx(y,z) := maxsol(xs(y,z));
> seqn(a,b,n) := makelist(a + (b-a)*k/n, k, 0, n);
> leftxys (ys,z) := ev(makelist([leftx (y,z), y], y, ys), numer);
> rightxys(ys,z) := ev(makelist([rightx(y,z), y], y, ys), numer);
> leftxys (seqn(2, 0.943, 10), -1);
> rightxys(seqn(0.943, 2, 10), -1);
>
> but with more calls to "leftxys" and "rightxys" at the end, and then I
> converted the output to a series of "\draw" commands for TikZ using a
> throway-ish Lua program.
>
> I'm not in a hurry anymore, and now I can try to learn better ways to
> find the points in level curves.
>
> Questions: 1) I got lots of messages like this one:
>
> rat: replaced 0.110751 by 110751/1000000 = 0.110751
>
> How do I silence them?
>
> And: 2) plot2d knows how to plot "contour levels". It certainly has
> separate functions for calculating the points of a level curve and for
> converting those points into commands for, say, gnuplot... is it easy
> to call just the function that calculates the points? How do I do
> that?
>
> Thanks in advance!
> Eduardo Ochs
> http://angg.twu.net/eev-maxima.html
>
>
> _______________________________________________
> Maxima-discuss mailing list
> Max...@li...
> https://lists.sourceforge.net/lists/listinfo/maxima-discuss
>
|