plot of an equation

5 views
Skip to first unread message

68th

unread,
May 1, 2023, 2:16:34 PM5/1/23
to fricas...@googlegroups.com
is it possible in FriCAS to draw an equation and not a function? y=1 or x=1 in Cartesian coordinates, for example?

Waldek Hebisch

unread,
May 1, 2023, 2:40:39 PM5/1/23
to '68th' via FriCAS - computer algebra system
On Mon, May 01, 2023 at 06:16:26PM +0000, '68th' via FriCAS - computer algebra system wrote:
> is it possible in FriCAS to draw an equation and not a function? y=1 or x=1 in Cartesian coordinates, for example?

Yes, but this is limited to algebraic functions. That is only
polynomial equations.

Example from the FriCAS book:

draw(x * y = 1, x, y, range == [-3..3, -3..3])

--
Waldek Hebisch

68th

unread,
May 2, 2023, 1:49:17 AM5/2/23
to fricas...@googlegroups.com

okay, does it work for polar or elliptic coordinates?

draw(x=1, x, y, range == [-3..3, -3..3])

does give a vertical line. and what if i want θ=1 in polar coordinates?

draw(t=1, t, r, range == [-%pi..%pi, -3..3], coordinates==polar)
plots a vertical line again as if the coordinates are still Cartesian. in polar coordinates θ=1 is a line running through the pole at the angle of elevation of 1 radian.


------- Original Message -------

--
You received this message because you are subscribed to the Google Groups "FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email to fricas-devel...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/fricas-devel/20230501192319.awmzhmmaavfngxzo%40fricas.math.uni.wroc.pl.

Waldek Hebisch

unread,
May 2, 2023, 7:25:06 AM5/2/23
to '68th' via FriCAS - computer algebra system
On Tue, May 02, 2023 at 05:49:08AM +0000, '68th' via FriCAS - computer algebra system wrote:
> okay, does it work for polar or elliptic coordinates?
>
> > draw(x=1, x, y, range == [-3..3, -3..3])
>
> does give a vertical line. and what if i want θ=1 in polar coordinates?
>
> > draw(t=1, t, r, range == [-%pi..%pi, -3..3], coordinates==polar)
>
> plots a vertical line again as if the coordinates are still Cartesian.

Yes, plots for solutions to equations ignore option for coordinates
and use cartesian coordinates.

--
Waldek Hebisch

68th

unread,
May 2, 2023, 7:46:43 AM5/2/23
to fricas...@googlegroups.com
thank you for letting me know about it. looks like FriCAS is missing something, which prevents me from using it for my purposes again.

------- Original Message -------
> --
> You received this message because you are subscribed to the Google Groups "FriCAS - computer algebra system" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to fricas-devel...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/fricas-devel/20230502120747.bprusaoa5mvxsb54%40fricas.math.uni.wroc.pl.

Waldek Hebisch

unread,
May 3, 2023, 9:17:37 AM5/3/23
to '68th' via FriCAS - computer algebra system
On Tue, May 02, 2023 at 11:46:32AM +0000, '68th' via FriCAS - computer algebra system wrote:
> thank you for letting me know about it. looks like FriCAS is missing something, which prevents me from using it for my purposes again.

Well, FriCAS is missing a lot of things. There is rich framework
and a lot of built in functionality, but it is normal that
developers simply can not predict all possible use cases.

FriCAS is user programable and frequently it is easy to add
what is wanted. ATM I can not say how much effort it
would take to implement what you want.

--
Waldek Hebisch

68th

unread,
May 4, 2023, 8:15:10 AM5/4/23
to fricas...@googlegroups.com

i guess this works:

draw(x=1, x, y, range == [-3..3, -3..3])


because the program uses Cartesian coordinates to make plots, and this command has everything to provide those [x=1, y=-3..3]. in case of other coordinate systems:

draw(t=1, t, r, range == [-3..3, -3..3], coordinates==polar)


there are no Cartesian coordinates and the polar(pt) and elliptic(a) functions are of no help because theta is constant. i think a simple solution might be as follows:

if t is not π/2 [incl. ±πn] then x=-3..3 and y=x*tan(theta).
if t=π/2 or t=3π/2 then x=0 and y=-3..3.

but that would work if the ranges are still for x and y for Cartesian coordinates and not for r and theta.

Waldek Hebisch

unread,
May 4, 2023, 5:30:01 PM5/4/23
to '68th' via FriCAS - computer algebra system
On Thu, May 04, 2023 at 12:15:03PM +0000, '68th' via FriCAS - computer algebra system wrote:
> i guess this works:
>
> > draw(x=1, x, y, range == [-3..3, -3..3])
>
> because the program uses Cartesian coordinates to make plots, and this command has everything to provide those [x=1, y=-3..3]. in case of other coordinate systems:
>
> > draw(t=1, t, r, range == [-3..3, -3..3], coordinates==polar)
>
> there are no Cartesian coordinates and the polar(pt) and elliptic(a) functions are of no help because theta is constant.

Well, as I wrote in another thread, coordinates work on top of
computation of points. First we get point (x, y), and then
ct((x,y)), where ct is coordinate transformation. ATM I am not
sure why equation plot does not support coordinate transformation.
One possiblity is that original author did not consider them useful.
Anothother may be confusion due to ranges: does range mean
orignal coordinates or the final ones.

> i think a simple solution might be as follows:
>
> if t is not π/2 [incl. ±πn] then x=-3..3 and y=x*tan(theta).
> if t=π/2 or t=3π/2 then x=0 and y=-3..3.
>
> but that would work if the ranges are still for x and y for Cartesian coordinates and not for r and theta.

One possiblity of getting transformations is to extract list of
intervals and transform them. One can do:

ob := makeObject(x^2 + y^2 = 1, x, y, range == [-1..1, -1..1])
llp := pointLists(ob)

that gives longish output giving you list of lists of points. Graph
may contain multiple curves, single curve is represented by list
of points. In principle one can transform each point to new
coordinates and in this way transform the whole graph. Namely

ptr := polar$CoordinateSystems(DoubleFloat)
llp1 := [[ptr(p) for p in lp] for lp in llp]

You can get it on the screen via

draw(first(llp1))

or

makeViewport2D(makeGraphImage(llp1)$GraphImage, [])$TwoDimensionalViewport

The first one ('draw') is considered user command, but can only
handle single curve. The second one can handle multiple curves
but the commands are not "exposed" so you need '$GraphImage' part
and '$TwoDimensionalViewport' to tell FriCAS where to find them
(or you could expose GraphImage and TwoDimensionalViewport).

The above has a problem: drawing functions make some effort to
get reasonable approximation to the curve. But after such
simple minded transformation approximation may no longer be
reasonable. For example, if equation is 'x = 1', then it is
a stright line and drawing code uses just two points (part
of line in range is an interval and drawing code just uses
this interval). But after nonlinear transform this will be
curved, so to represent it accurately we need intermediate points.

--
Waldek Hebisch

68th

unread,
May 5, 2023, 3:21:32 PM5/5/23
to fricas...@googlegroups.com

------- Original Message -------


On Thursday, May 4th, 2023 at 9:30 PM, Waldek Hebisch de...@fricas.math.uni.wroc.pl wrote:

Well, as I wrote in another thread, coordinates work on top of computation of points. First we get point (x, y), and then ct((x,y)), where ct is coordinate transformation. ATM I am not sure why equation plot does not support coordinate transformation. One possiblity is that original author did not consider them useful. Anothother may be confusion due to ranges: does range mean orignal coordinates or the final ones.

One possiblity of getting transformations is to extract list of intervals and transform them. One can do:

ob := makeObject(x^2 + y^2 = 1, x, y, range == [-1..1, -1..1])
llp := pointLists(ob)

that gives longish output giving you list of lists of points. Graph may contain multiple curves, single curve is represented by list of points. In principle one can transform each point to new coordinates and in this way transform the whole graph. Namely

ptr := polar$CoordinateSystems(DoubleFloat)
llp1 := [[ptr(p) for p in lp] for lp in llp]

You can get it on the screen via

draw(first(llp1))

thank you for introducing me to FriCAS commands related to plotting.

judging from what you said, this command:

draw(first(pointLists(makeObject(1, t=0..2*%pi, coordinates==polar))))

as well as this one:

draw(1, t=0..2*%pi, coordinates==polar)

don't do the transformation you are talking about and yet produce same correct plots in polar coordinates. a user gives a function in polar coordinates and gets a plot in polar coordinates. why would he want a polar graph for a Cartesian function? as far as i understand, the problem is not in transforming a graph, but in making the program treat some implicit functions in non-Cartesian coordinates properly. correct me if i'm wrong, pointLists always returns points in Cartesian coordinates, so real transformation [polar(pt), elliptic(a), etc] should occur either in pointLists itself or in makeObject. probably, in the former.

Waldek Hebisch

unread,
May 6, 2023, 8:52:50 PM5/6/23
to '68th' via FriCAS - computer algebra system
On Fri, May 05, 2023 at 07:21:13PM +0000, '68th' via FriCAS - computer algebra system wrote:
> ------- Original Message -------
> On Thursday, May 4th, 2023 at 9:30 PM, Waldek Hebisch de...@fricas.math.uni.wroc.pl wrote:
>
>
> judging from what you said, this command:
>
> > draw(first(pointLists(makeObject(1, t=0..2*%pi, coordinates==polar))))
>
> as well as this one:
>
> > draw(1, t=0..2*%pi, coordinates==polar)
>
> don't do the transformation you are talking about and yet produce
> same correct plots in polar coordinates.

Correct depends on what user want. In first command above
'makeObject' is doing transformation from polar to cartesion coordinates.

In the second the same thing is done by 'draw' (in fact, draw calls
'makeObject').

> a user gives a function in polar coordinates and gets a plot in
> polar coordinates. why would he want a polar graph for a Cartesian function?

Our terminalogies differ: I would say that plot is in cartesion
coordinates. Concerning usefulness, usually coordinates are used
to get simpler view. For example, drawing circle in polar coordinates
(that is drawing points with polar coordinates of point on the
circle) gives an interval, which is much simpler than circle.
If graph of a function is subset of circle, that drawing it in
polar coordinates would make it simpler. Besides graphs of
functions, FriCAS can draw curves. If you take Keplerian
orbit of a planet, than looking at polar coordinates of points
gives particularly simple view.

More generally, FriCAS covers _huge_ part of mathematics. To
understand and use it we need consistent terminology that
span many math domains. Unfortunately in many field people
make conventions that are "locally" useful, but in many
cases contradict what is done/useful in different domains.
Fortunately, FriCAS documatation say "transformation" and
spells out details.

> as far as i understand, the problem is not in transforming a graph,
> but in making the program treat some implicit functions in non-Cartesian
> coordinates properly. correct me if i'm wrong, pointLists always returns
> points in Cartesian coordinates,

Well, pointLists ultimately consists of Points, that is element of
FriCAS type Point. Point is representd using coordinates which
one could call cartesian, but I am affraid that this is different
meaning of cartesian that you use.

In normal operation transformations are applied before you could
access point list, and functions that draw point lists do not
perform nontrivial transformations (graphic windows have options
for scaling and rotations and this is done on point lists).
However, as I showed, user can apply transformation to point
list.

> so real transformation [polar(pt), elliptic(a), etc] should occur either in pointLists itself or in makeObject. probably, in the former.

Core part of drawing is producing point lists, this is done in
functions called form 'makeObject'. 'pointLists' merely accesses
already created point lists. Note that FriCAS uses overloading
and there are several 'makeObject' functions organized into
layers. Upper layer merely converts arguments and delegates
real work to lower layer.

Coming back to curves given by equations: one needs to inserts
transformation in correct place. Finding correct place
probably is not very difficult, but is not entirely obvious
either. As I wrote, drawing code tries to ensure that point
lists are good approximation to the curve. That involves
some arithmetic which in case of curves given by equations
it mixed with equation solving.

--
Waldek Hebisch

68th

unread,
May 7, 2023, 8:19:20 AM5/7/23
to fricas...@googlegroups.com

thank you again for explaining to me how FriCAS works internally.

Our terminalogies differ: I would say that plot is in cartesion coordinates.

okay. i use words 'plot' and 'graph' interchangeably but in this case let's make a distinction between them. graph is a visual representation of a function or equation. if the function or equation is polar then its graph is also polar. and plot is a list of points in Cartesian coordinates, although the points may approximate a non-Cartesian graph.

that being so, my phrase should be as follows:

a user gives a function in polar coordinates and gets a graph in polar coordinates.

though in fact he gets a plot approximating the polar graph. but that's what the user wanted because now he is able to see what the polar graph looks like.

Point is representd using coordinates which one could call cartesian, but I am affraid that this is different meaning of cartesian that you use.

i think now we have one and the same meaning for Cartesian coordinates.

Coming back to curves given by equations: one needs to inserts transformation in correct place. Finding correct place probably is not very difficult, but is not entirely obvious either.

there's only one place where transformation occurs. like you said:

... 'makeObject' is doing transformation from polar to cartesion coordinates.


As I wrote, drawing code tries to ensure that point lists are good approximation to the curve. That involves some arithmetic which in case of curves given by equations it mixed with equation solving.

somehow makeObject understands that graph of the Cartesian equation x=constant is a straight line and it only takes two points to draw a plot:

-> pointLists(makeObject(x=1, x, y, range==[-3..3,-3..3]))

[[[1.0, 3.0], [1.0, - 3.0]]]

for the polar equation theta=constant the graph is also a straight line and instead of ignoring the coordinates option:

-> pointLists(makeObject(t=1, t, r, range==[-3..3,-3..3], coordinates==polar))

[[[1.0, 3.0], [1.0, - 3.0]]]

because polar(pt) won't work here, makeObject should return this:

[[[3.0, 1.9262778478], [-3.0, -1.9262778478]]]

and that requires dealing with non-Cartesian polynomial equations. i don't know how it works for Cartesian ones, so have no idea if there would be any differences.

by the way, why is a linear function plotted as if its slope is always 1? try this for example:

-> draw(10*x, x = -3..3)

or -1 if the slope is negative.

Waldek Hebisch

unread,
May 7, 2023, 9:37:42 AM5/7/23
to '68th' via FriCAS - computer algebra system
On Sun, May 07, 2023 at 12:19:03PM +0000, '68th' via FriCAS - computer algebra system wrote:
>
> by the way, why is a linear function plotted as if its slope is always 1? try this for example:
>
> -> draw(10*x, x = -3..3)
>
> or -1 if the slope is negative.

Well, that is "fit into available window" feature. Click on Units
button in control panel to turn Unit on, you will see that function
values change much more than arguments.

And what did you expect? Having ony small part of the graph and
rest clipped?

--
Waldek Hebisch

68th

unread,
May 7, 2023, 1:37:31 PM5/7/23
to fricas...@googlegroups.com

------- Original Message -------


On Sunday, May 7th, 2023 at 1:37 PM, Waldek Hebisch de...@fricas.math.uni.wroc.pl wrote:

Well, that is "fit into available window" feature. Click on Units
button in control panel to turn Unit on, you will see that function
values change much more than arguments.

okay, i see. is there a way to disable it from the command line?

And what did you expect? Having ony small part of the graph and
rest clipped?

i think this defeats the purpose of graphs as a visual representation as opposed to tabular form or any other form with a list of numbers. a user should control what part of the graph he wants to see by changing the ranges.

Waldek Hebisch

unread,
May 7, 2023, 4:36:50 PM5/7/23
to '68th' via FriCAS - computer algebra system
On Sun, May 07, 2023 at 05:37:17PM +0000, '68th' via FriCAS - computer algebra system wrote:
> ------- Original Message -------
> On Sunday, May 7th, 2023 at 1:37 PM, Waldek Hebisch de...@fricas.math.uni.wroc.pl wrote:
>
> > Well, that is "fit into available window" feature. Click on Units
> > button in control panel to turn Unit on, you will see that function
> > values change much more than arguments.
>
> okay, i see. is there a way to disable it from the command line?

Try:

draw(10*x, x = -3..3, toScale==true)

> > And what did you expect? Having ony small part of the graph and
> > rest clipped?
>
> i think this defeats the purpose of graphs as a visual representation as opposed to tabular form or any other form with a list of numbers. a user should control what part of the graph he wants to see by changing the ranges.

Well, if you care about actual values then tabular form is better.
IMHO graphs are to get rough idea of values (for that turning on
units is enough) and mainly to see qualitative behaviour: if/when
function increases/decrease, to see curvature, to look for zeros
and similar.

--
Waldek Hebisch

68th

unread,
May 8, 2023, 1:40:58 AM5/8/23
to fricas...@googlegroups.com

------- Original Message -------


On Sunday, May 7th, 2023 at 8:37 PM, Waldek Hebisch de...@fricas.math.uni.wroc.pl wrote:

Try:

draw(10*x, x = -3..3, toScale==true)

yes, that's much better. thank you.

Reply all
Reply to author
Forward
0 new messages