Improving the MATLAB function "simple"
flag
Messages 1 - 10 of 261 - Collapse all
/groups/adfetch?adid=Sa2DxREAAAD_hH6pNUQBDlkUHIOpBEpkFSRgCP-avRN4YT0eROC0jw
Improving the MATLAB function "simple"  
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
1.  dev...@math.udel.edu  
View profile  
 More options Sep 1 2005, 2:02 am
Newsgroups: comp.soft-sys.matlab, comp.soft-sys.math.maple, sci.math.symbolic
From: dev...@math.udel.edu
Date: 31 Aug 2005 23:02:58 -0700
Local: Thurs, Sep 1 2005 2:02 am
Subject: Re: Improving the MATLAB function "simple"

JohnCreight...@hotmail.com wrote:
> dev...@math.udel.edu wrote:
> > As I've tried to show you in other posts, the way to get better
> > simplifications is to get the simplifying routines to make better use
> > of the assumptions, and a good way to do this is to simplify the
> > assumptions and break them down into cases.  Using redundant
> > assumptions can work well.  (What we are calling "assumptions" are more
> > often called "constraints".)

> Redundant assumptions can slow a program down so much it will never
> finish.

Yes, but the prudent use of redundant assumptions can be very useful.
There has much research on this in the past few years.  Look up
"redundant modeling" and "constraint propagation".  In the case of the
example that you used to start this thread (shown far below), we
already saw that 'combine' quickly handles the assumptions in the
multiplied together form, whereas 'simplify' will only do anything
useful with the assumption factored into cases.  By making the
assumptions redundantly in both forms, both simplify and combine would
be to do something useful with the expression.

> Also breaking down expressions means you are doing more work and the
> computer is doing less.

I meant that you would achieve better results by **writing a program**
that breaks down the assumptions than you would by applying the various
simplifiers in sucession as you described.

Here is a program that processes assumptions in this manner.  First, an
example.

> restart;
> expr:= (x^3*y^3)^(1/3);

                                   3  3 (1/3)
                         expr := (x  y )

Suppose that we want to simplify the above radical expression under the
assumption that the variables are real and x*y > 0.  Maple's 'simplify'
is not very good at processing multivariate inequality assumptions.

> simplify(expr, radical) assuming x::real, y::real, x*y>0;

                               3  3 (1/3)
                             (x  y )

But in high school algebra we learn that inequalities of products can
be divided into cases of inequalities of the factors.

> simplify(expr, radical) assuming x>0, y>0;

                                 x y

> simplify(expr, radical) assuming x<0, y<0;

                                 x y

Since both simplifications are the same, we can say that the answer is
simply x*y.

Maple's 'assuming' facility cannot handle multivariate disjunctive
assumptions.

> simplify(expr, radical) assuming x<0 and y<0 or x>0 and y>0;

Error, (in assuming) when calling 'assume/ProcessTerm'. Received: 'x <
0 and
y < 0 or 0 < x and 0 < y is an invalid property'

With a little thought, we can see that the only way to process such a
disjunction is to perform the operation separately with each disjunct.
That is what the procedure below does.

AssumeFactorableInequality:= proc(expr::uneval, Ineq::{`<`, `<=`})
   option `Copyright (C) 2005, Carl James Love.  All rights reserved.`;
   local
      ineq, k, negfactors, NF, assumptions, Simps, Reduced
     ,A, A1, A2, S1, S2, Checked, pair, C, negated, Rel
   ;
   Rel:= op(0, Ineq);  # `<` or `<=`
   ineq:= factor((rhs-lhs)(Ineq));
   # Thus Ineq is equivalent to (0 Rel ineq).

   # If the inequality cannot be factored,
   # then there is not much more that this procedure can do.
   if not ineq::`*` then
      return eval(expr) assuming Rel(0,ineq), Ineq
   fi;

   # Factor out constants and check sign of their product.
   C,ineq:= selectremove(type, ineq, constant);
   if is(evalf(C)<0) or is(C<0) then negated:= true
   elif is(evalf(C)>0) or is(C>0) then negated:= false
   else error "Cannot determine sign of constant expression %1.", C
   fi;

   # If there's only one nonconstant factor,
   # then there is not much more that this procedure can do.
   if not ineq::`*` then
      return eval(expr) assuming Rel(0,`if`(negated,-1,1)*ineq), Ineq
   fi;

   # For every even subset of the factors (counting the product of the
   # constants as one factor iff it is negative), evaluate expr under
the
   # assumption that the members of that subset are negative and the
other
   # factors are positive.  Save the evaluated expressions in a table
   # indexed by the assumptions.
   ineq:= {op}(ineq);
   for k from `if`(negated, 1, 0) by 2 to nops(ineq) do
      negfactors:= combinat[choose](ineq,k);
      for NF in negfactors do
         assumptions:= map(Rel,NF,0) union map2(Rel,0,ineq minus NF);
         Simps[foldl(`and`, true, assumptions[])]:=
            eval(expr) assuming assumptions[], Ineq
      od
   od;

   # For every pair of evaluations, check if the evaluated forms are
   # equivalent. If they are, then replace the two entries in the table
by
   # the single evaluated form indexed by the disjunction of the two
   # assumptions.  Continue this until a full pass is made through the
table
   # with no pairs reduced.  If at any point there is only one
evaluated form
   # in the table, then we can return that form and quit.
   Reduced:= true;
   while Reduced do
      Reduced:= false;
      assumptions:= map(op, [indices](Simps));
      if nops(assumptions)=1 then return Simps[assumptions[]] fi;
      A:= combinat[choose](assumptions,2);
      for pair in A do
         A1,A2:= op(pair);
         S1:= Simps[A1]; S2:= Simps[A2];
         if not (assigned(S1) and assigned(S2))
            or assigned(Checked[{A1,A2}])
         then
            next
         fi;
         Checked[{A1,A2}]:= true;  # Each pair only needs to be checked
once.
         if simplify(S1-S2) = 0 or (simplify(S1-S2) = 0 assuming Ineq)
then
            Reduced:= true;
            unassign('Simps[A1]', 'Simps[A2]');
            Simps[A1 or A2]:= `if`(length(S1)<length(S2), S1, S2)
         fi
      od
   od;

   # If we get here, then the table Simps has at least two evaluated
forms
   # which cannot be proven to be equal.  Return them as a piecewise
   # construct.
   piecewise(seq([A,Simps[A]][], A in map(op, [indices](Simps))))
end proc:

Now back to the first example.

> AssumeFactorableInequality(simplify(expr, radical), x*y > 0);

                                 x y

If the disjuncts yield distinct simplifications, then a piecewise form
is returned.

> AssumeFactorableInequality(simplify((x^4*y^3)^(1/2), radical), x*y > 0);

               {     2       1/2
               { -I x  y (-y)           x < 0 and y < 0
               {
               {     2  (3/2)
               {    x  y                0 < x and 0 < y

Now let's do the example that started this thread.

> p:=-(Ps1_1*Ppa1_1+Ps_ps1_1^2)/Ppa1_1:
> d:= 1/(sqrt(p)*sqrt(1/p)):
> AssumeFactorableInequality(simplify(d, radical), p>0);

                                  1

    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
2.  johncreight...@hotmail.com  
View profile  
 More options Sep 2 2005, 6:06 pm
Newsgroups: comp.soft-sys.matlab, comp.soft-sys.math.maple, sci.math.symbolic
From: JohnCreight...@hotmail.com
Date: 2 Sep 2005 15:06:37 -0700
Local: Fri, Sep 2 2005 6:06 pm
Subject: Re: Improving the MATLAB function "simple"
I am impressed by you code and you technique does seem to solve my
problem. I have hover started my own post about an alternative method.
I feel the alternative method will be more general and powerful.
However, this could just be from a lack of understanding I have about
how your method works.


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
plotting changed implicitplot3d data  
1.  smango  
View profile  
 More options Sep 2 2005, 6:40 am
Newsgroups: comp.soft-sys.math.maple
From: "smango" <sm...@rumms.uni-mannheim.de>
Date: 2 Sep 2005 03:40:42 -0700
Local: Fri, Sep 2 2005 6:40 am
Subject: plotting changed implicitplot3d data
Hi there,

I want to evaluate a function for points on the unit sphere. I read an
article in this newsgroup on how to access the data from an
implicitplot

s:=implicitplot3d(x^2+y^2+z^2-1=0, x=-1..1, y=-1..1, z=-1..1,
numpoints=4000);

I changed the points in the resulting array.

But how do I plot the results? I don't even know how to lot s without
changes.

Please help me,

Smango


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
2.  Preben Alsholm  
View profile  
 More options Sep 2 2005, 7:29 am
Newsgroups: comp.soft-sys.math.maple
From: Preben Alsholm <P.K.Alsh...@mat.dtu.dk>
Date: Fri, 02 Sep 2005 13:29:58 +0200
Local: Fri, Sep 2 2005 7:29 am
Subject: Re: plotting changed implicitplot3d data

smango wrote:
> s:=implicitplot3d(x^2+y^2+z^2-1=0, x=-1..1, y=-1..1, z=-1..1,
> numpoints=4000);

> I changed the points in the resulting array.

> But how do I plot the results? I don't even know how to lot s without
> changes.

That should be really simple. Just enter s on an input line an press ENTER:

 > with(plots):

 > s:=implicitplot3d(x^2+y^2+z^2-1=0, x=-1..1, y=-1..1, z=-1..1,

 > numpoints=4000):

 > s;

Preben Alsholm


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
3.  smango  
View profile  
 More options Sep 2 2005, 8:14 am
Newsgroups: comp.soft-sys.math.maple
From: "smango" <sm...@rumms.uni-mannheim.de>
Date: 2 Sep 2005 05:14:48 -0700
Local: Fri, Sep 2 2005 8:14 am
Subject: Re: plotting changed implicitplot3d data
Thank you!
Now I have a new problem. The evaluation does not seem to work
correctly.
Does anybody have a suggestion on how to generate the points on a
sphere and lateron plot them in 3D?

Smango


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
4.  dev...@math.udel.edu  
View profile  
 More options Sep 2 2005, 1:35 pm
Newsgroups: comp.soft-sys.math.maple
From: dev...@math.udel.edu
Date: 2 Sep 2005 10:35:14 -0700
Local: Fri, Sep 2 2005 1:35 pm
Subject: Re: plotting changed implicitplot3d data

smango wrote:
> Does anybody have a suggestion on how to generate the points on a
> sphere and lateron plot them in 3D?

Since you started by mentioning implicitplot3d, I'll describe how this
is done.  Of the various methods of plotting a surface, implicit is the
one which will always work; but it gives the lowest quality plot
(still, not bad), and requires the generation and memory storage of a
huge amount of extraneous data.

We represent the surface as a function of 3 (not 2) variables,
f(x,y,z), such that f(x,y,z) = 0 for points (x,y,z) on the surface.
So, for the unit sphere:

f:= (x,y,z)-> x^2+y^2+z^2-1:

We need to evaluate this function over a 3D grid of points.  Let's say
we use 8000 points, 20 for each dimension (20^3 = 8000).

N:= 8000:
n:= round(evalf(N^(1/3)));
                      n := 20

It is not necessary to use the same number for each dimension.

We need a **four**-dimensional array to hold the data:

Pts:= Array(1..n, 1..n, 1..n, 1..4, datatype= float[8]):

The last dimension is always 1..4.  We'll see why in a moment.  An
array such as this is probably the numeric data structure you got when
you picked apart the result of an implicitplot3d command.

We need ranges for x, y, and z.  In the example, let's make the range
-1.2 .. 1.2 for each:

xlo,xhi:= op(-1.2 .. 1.2):
ylo,yhi:= op(-1.2 .. 1.2):
zlo,zhi:= op(-1.2 .. 1.2):

So we have a rectangular block of 3D space, in this case [-1.2 ..
1.2]^3.  We put the grid in this block, and evaluate the function at
each gridpoint.  I'll make the grid evenly spaced, although it does not
need to be that way.

for i to n do  for j to n do  for k to n do
   x:= evalf(xlo+(xhi-xlo)*(i-1)/(n-1));
   y:= evalf(ylo+(yhi-ylo)*(j-1)/(n-1));
   z:= evalf(zlo+(zhi-zlo)*(k-1)/(n-1));
   Pts[i,j,k,1..4]:= rtable([x,y,z,f(x,y,z)])
od od od:

To plot it:

PLOT3D(ISOSURFACE(Pts));

To further manipulate the plot, save it in a variable

Myplot:= %:

and use plots[display] to make feature changes:

plots[display](Myplot, title= "My plot", axes= boxed);

There are three numeric data structures that are used to represent
plotted surfaces:  ISOSURFACE, MESH, and GRID.  The details are given
at ?plot,structure.  I'll explain the GRID and MESH later if there is
interest.


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
5.  Robert Israel  
View profile  
 More options Sep 2 2005, 7:32 pm
Newsgroups: comp.soft-sys.math.maple
From: isr...@math.ubc.ca (Robert Israel)
Date: 2 Sep 2005 23:32:47 GMT
Local: Fri, Sep 2 2005 7:32 pm
Subject: Re: plotting changed implicitplot3d data
In article <1125682514.342598.299...@g43g2000cwa.googlegroups.com>,

 <dev...@math.udel.edu> wrote:
>smango wrote:
>> Does anybody have a suggestion on how to generate the points on a
>> sphere and lateron plot them in 3D?
>Since you started by mentioning implicitplot3d, I'll describe how this
>is done.  Of the various methods of plotting a surface, implicit is the
>one which will always work; but it gives the lowest quality plot
>(still, not bad), and requires the generation and memory storage of a
>huge amount of extraneous data.

...

... and the point is that the ISOSURFACE data structure doesn't contain
points on a sphere at all, it depends on the rendering software to
contstruct an approximate surface by interpolation.

To create a data structure that does contain points on a sphere, you
could use plottools[sphere].  This actually produces a POLYGONS structure.
The sequence of points involved could equally well be produced by

  seq(seq([x0 + r*cos(2*j*Pi/m)*sin(2*k*Pi/n),
           y0 + r*sin(2*j*Pi/m)*sin(2*k*Pi/n),
           z0 + r*cos(2*k*Pi/n)], k=0..n-1), j=0..m-1);

where m and n are positive integers (for a sphere of radius r centred
at [x0,y0,z0]).

Robert Israel                                isr...@math.ubc.ca
Department of Mathematics        http://www.math.ubc.ca/~israel
University of British Columbia            Vancouver, BC, Canada


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
6.  smango  
View profile  
 More options Sep 8 2005, 5:02 am
Newsgroups: comp.soft-sys.math.maple
From: "smango" <sm...@rumms.uni-mannheim.de>
Date: 8 Sep 2005 02:02:05 -0700
Local: Thurs, Sep 8 2005 5:02 am
Subject: Re: plotting changed implicitplot3d data
Thanks for your tip, I tried that, but how do I plot these points. I
tried to plot (with listplot3d) a sphere from the sequence but the
result looks more like a wavy ocean. Is there a way for Maple to sort
the points by itsef?

Regards,
Smango


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
7.  Robert Israel  
View profile  
 More options Sep 8 2005, 2:36 pm
Newsgroups: comp.soft-sys.math.maple
From: isr...@math.ubc.ca (Robert Israel)
Date: 8 Sep 2005 18:36:12 GMT
Local: Thurs, Sep 8 2005 2:36 pm
Subject: Re: plotting changed implicitplot3d data
In article <1126170125.483578.171...@g43g2000cwa.googlegroups.com>,

smango <sm...@rumms.uni-mannheim.de> wrote:
>Thanks for your tip, I tried that, but how do I plot these points. I
>tried to plot (with listplot3d) a sphere from the sequence but the
>result looks more like a wavy ocean. Is there a way for Maple to sort
>the points by itsef?

Try pointplot3d to plot the points as points.  If you want a
surface, you'll have to organize them in a list of lists of points
or an Array of points.  

Robert Israel                                isr...@math.ubc.ca
Department of Mathematics        http://www.math.ubc.ca/~israel
University of British Columbia            Vancouver, BC, Canada


    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Double underline in maple?  
1.  Paminu  
View profile  
 More options Sep 2 2005, 8:08 am
Newsgroups: comp.soft-sys.math.maple
From: "Paminu" <as...@asd.com>
Date: Fri, 2 Sep 2005 14:08:42 +0200
Local: Fri, Sep 2 2005 8:08 am
Subject: Double underline in maple?
Is it possible to double underline a word?

    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.

Create a group - Google Groups - Google Home - Terms of Service - Privacy Policy
©2010 Google