acer

32450 Reputation

29 Badges

20 years, 0 days
Ontario, Canada

Social Networks and Content at Maplesoft.com

MaplePrimes Activity


These are replies submitted by acer

@Andiguys Why don't you ask state all your requirements when you first post your Question?

You can use Kitonum's code for 2D contour plotting with labelled curves here. (You could also easily find that by doing a simple search on this site.) You can use that code it with the interpolating function in my earlier response above.

@Andiguys 

You have two choices, as far as using an external file goes and how you can reference it in the string passed to the ImportMatrix command. 1) use an absolute/full path, or 2) use a path relative to the currentdir(...) setting.

On Windows the choice 1) absolute path would look like, say,
  "C://Users/Andiguys/foo/data.txt"
or wherever you have actually put the file on your computer.

Suppose that the file is at "C://Users/Andiguys/foo/data.txt" and that currentdir(...) is set to, say,
   "C://Users/Andiguys"
then for the choice 2) the relative path would be just, "foo/data.txt" .

In my example I had currentdir(...) already set to the very folder/directory in which the file resided. So the relative path, for me, was just the filename by itself.

You don't have to use an external file. Your data could just start out life in a Matrix, say. I can't tell you how to adjust your code for that since you didn't give us your code.

@Andiguys I'm not entirely sure what you mean by, "...a 2D graph with x and y axes, where the z value is displayed along the curve at specific points."

I am supposing that you mean a 2D contour plot.

I'll do something a little different below, and construct an interpolating function from your data.

That can be used to obtain the same 3D surface as before. But it can also be used to produce a 2D contour plot.

In fact, it can be used like any other "function" of two variables, for plotting or polling pairs of values in your data's independent ranges. So even if my supposition about what you now want is mistaken then the interpolant can likely be used to attain the goal.

restart;

with(plots):

M := ImportMatrix("data.txt", source=csv)[..,2..4]:

R := Array(ArrayTools:-Reshape(M,[7,4,3]),datatype=float[8]):


Create an interpolating function from the data.

func := Interpolation:-SplineInterpolation([[$1..7],[80,85,95,100]],R[..,..,3]):


Show that the interpolant agrees with the surfdata surface.

display(
  plot3d(func(x,y),y=80..100,x=1..7,style=point,color=blue,
         grid=[5,5],symbolsize=15,symbol=solidcircle),
  surfdata(R, color=green)
);

conts := [seq(min(R[..,..,3])..max(R[..,..,3]),0.05)];

[HFloat(1.364583951), HFloat(1.414583951), HFloat(1.464583951), HFloat(1.5145839509999999), HFloat(1.564583951), HFloat(1.614583951), HFloat(1.664583951), HFloat(1.7145839509999998), HFloat(1.764583951)]

CP2 := contourplot(func(x,y), x=1..7, y=80..100,
                   contours=conts, coloring=["Blue","Gold"]):

CP2;


Show that the 2D contour plot agrees with the contours of the 3D surface.

display(
  plot3d(func(x,y),x=1..7,y=80..100,
         style=contour,contours=conts,
         colorscheme=["zgradient",["Blue","Gold"]]),
  plottools:-transform((x,y)->[x,y,1.3])(CP2),
  thickness=4
);


some_data_plot_3.mw

@C_R How is the second approach the best? The first is much faster and simpler, and completely avoids the float-roundoff (Pi) edge idiosyncrasy & need for higher grid values.

Cannot the individual portions all be exported to STL just as easily as the conjoined result from the second approach? I would expect that they can (even if done separately).

@C_R The first approach seems better all round. Why would you use the second approach?

The two kinds of gap can be reduced by increasing the corresponding grid option values.

You may be able to get by there with NULL instead of undefined (I had other variants where it had an effect). The key bit is adaptmesh=false.

But the first way is so much simpler, and faster and lightweight, that I don't understand any preference for using the second.

While it's not nearly as fast and simple as the above, the original methodology can be hammered into something that omits those conjoining artefacts.
1) Using adaptmesh=false to prevent plot3d from trying extra hard to stitch together pieces adjacent in the data structure.
2) split by undefined rather than NULL
3) increase the grid resolution.

restart;

rmod:= (t,n)->(round@((x->x)-floor))(n*t):

f:=(t,p)-> ifelse(is(rmod(t,4/(2*Pi))+rmod(p,4/(2*Pi))=1),1,NULL):

p1:=plot3d(f,0..2*Pi,0..Pi,coords=spherical,scaling=constrained,
           color="black",grid=[200,200],style=surface,adaptmesh=false):

p2:=plots:-sphereplot(0.999,theta=0..2*Pi,phi=0..Pi,color=white,style=surface):

plots:-display(p1,p2);


Download Chessboard_sphere_ac2.mw

Maple automatically transforms 1/2^(1/4) and 2^(-1/4) into 1/2*2^(3/4) .

That happens as a result of what's called automatic simplification, and cannot be avoid just by unevaluation. That is, it'd also happen for '1/2^(1/4)', ie. wrapped in single right-quotes (aka uneval quotes).

It should be possible programatically to turn it into an inert form and have that be displayed without the automatic simplification. Then you could get the output rendered as follows (or with 2^(-1/4) in the numerator):

restart;

with(InertForm):

'1/2^(1/4)';

(1/2)*2^(3/4)

'2^(-1/4)';

(1/2)*2^(3/4)

foo := something / 2 %^ (1/4):

value(foo);

(1/2)*something*2^(3/4)

Display(foo,'inert'=false);

something/Typesetting:-_Hold([`%^`(2, 1/4)])


Download inert_p_ex.mw

ps. Are you also wanting to simplify wrt that B^2 inside the square-root? Is B real?
Also, you have a term like e^(i*psi(x,t)), so is that deliberate that you don't use I and exp?

@salim-barzani Right the simplify command will not produce the results you want in Maple 2021.

That's why I showed you how it might be done using applyrule.

Is it the performance of the Maple GUI which is slow, or computation of results that is slow (even when run in both systems with all display of output results suppressed, etc)?

If it's the computation, then what computation?

@salim-barzani I've already showed you (above) that your given examples can be handled automatically by Maple 2024 by just the simplify command.

Such simplifications can also usually be restricted (eg. simplify(...,trig), etc) so that they don't alter other type of term.

You ask whether all your other Maple 2021 code (which you don't provide here) will run the ok in Maple 2024. It's likely that it will. But nobody can make such a prediction with 100% guarantee, without seeing the code.

Please put your followup examples on this here, instead of in wholly separate new Question threads,

@Ronan I added a response to your earlier Question thread on rotated text in a 2D plot.

@erik10 A terser variant on that is something like,

  Circle1 := ifelse(CircleOrNot="yes", circle(...), NULL);

or, when CircleOrNot is definitely assigned one of true or false,

  Circle1 := ifelse(CircleOrNot, circle(...), NULL);

@adam25185 Could you please upload and attach your full worksheet file, using the green up-arrow in the Mapleprimes editor?

@salim-barzani You're very welcome.

Please note that I put a line,

   indets(F, function)

into the sheet. That sort of thing can be useful, as a kind of check. In the original, it showed the long expressions that were just function calls of l and m.

You can also do it as,

   lprint(indets(F, function))

and get its result line-printed as 1-D code, if that helps diagnosis.

First 27 28 29 30 31 32 33 Last Page 29 of 594