EGalceran

10 Reputation

One Badge

9 years, 179 days

MaplePrimes Activity


These are questions asked by EGalceran

I have a function which calculates a number for [x,y] inside a matrix, which depends on the values surrounding said initial cell (from [x-1,y-1] yo [x+1,y+1]). However, for the values on the border, the idea is to go around to the opposite side, creating a Torus of the sort.
The solution I seemed to have found was to create 4 indices: 2 controled with 'for' and 2 which were modified accordingly to be used as imputs for the function:

x:=x0;y:=y0;
for r from x-1 to x+1 do
    print("r",r);
    for t from y-1 to y+1 do
        print("t",t);
        if r=0 then i:=N; else i:=r; fi;
        if t=0 then j:=N; else j:=t; fi;
        if r=N+1 then i:=1; else i:=r; fi;
        if t=N+1 then j:=1; else j:=t; fi;
        print("i",i);print("j",j);
        function(i,j);
od; od;
 

(the print commands are for the tests I have been running so see where the potential error lied).
If you run this script, you can clearly see for x0,y0<>1 that it works perfectly, even for x0,y0=N where it succesfully goes around and changes to 1. However, for x0,y0=1 it isn't able to detect that r&t=0 and so it doesn't change it to N; creating an error where it tries to find the value 0 of an Array.

Thanks in advance,
Enrique

Hello!

I am working in a simulation, which requires me to create a checkerboard of values which I paint afterwards according to its value. The idea is to create a sequence of images (which I could export for every iteration and create into a gif/timelapse afterwards). The problem I am encountering is that when I try to plot it, I only obtain a difuse coloring scheme, without having a specific color for every pixel.

if you search for the color command in plots (http://www.maplesoft.com/support/help/Maple/view.aspx?path=plot/color) one of the examples is more or less the result I want, but I would like to have it without the gridlines and being able to control the color according to the value of the matrix in said position.

 

My current attempt, and the one closest to the solution is:

 

R:=Matrix(1..N,1..N, datatype=integer); for x from 1 to N do for y from 1 to N do R[x,y]:=P[x,y,2]*18+P[x,y,3]: od: od:R;
#P is the matrix where I do the calculations and R is the matrix I want to plot after every step of the calculation.

surfdata(Matrix(R), 1..N, 1..N, style=surface,
         dimension=2, labels=["x", "y"],
         gridsize=[100,100],
         colorscheme=["zgradient",
                      ["Indigo","Blue","Cyan","Green","Yellow","Orange","Red"]]);
#the surfdata I resqued from another proyect I had. I know it is not thought for this tipe of grafs, but it was the closest I could come by.

 

I do not know if it is a better idea to use an Array or a Matrix to plot this. While the P array isn''t touched, I do not mind modifying in any way the R matrix

Thank you,

Enrique
 

Hello!

I am calculating the temperature of a rod which has one end at the temperature T1 and the other end at T2 and it's evolution. We were already given the formula for the numeric calculation and after a short while I managed to obtain a small program that would calculate the temperature of each segment of the T(x,t) grid:

>restart: with(plots): nx:=20: tmax:=50: T1:=1: T2:=10: L:=1: k:=1: rho:=1: cp:=1: chi:=k/rho/cp: h:=L/(nx-1): t:=1e-3:
>for k from 0 to nx do T(k,0):=T1 od:
for w from 1 to tmax do
T(0,w):=T1: T(nx,w):=T2:
for q from 1 to nx-1 do
T(q,w):=T(q,w-1)+chi*t/h^2*(T(q+1,w-1)+T(q-1,w-1)-2*T(q,w-1));
od: od:

With L the Length of the rod, t and h the time and space increment [h=L/(nx-1), where nx is the number of intervals we divide the x-axis, although I'm not quite sure the '-1' should be there], chi a constant different for each rod and tmax total time we want to calculate. The formula from the 5th line was given to us, so in that part there is no mistake.

Up until here everything works perfectly fine.

Now I want to be able to draw this and here is where all the problems appear. I want to draw this in a 2D graph with position in the x-axis and time in the y-axis. I have tried "densityplot(T(x,y),x=0..nx,y=0..tmax)" which would seem to be the logical whay to continue this. As I understand it, this plot would draw an nx times tmax grid and colour the whole plpot black-white acording to the maximum and the minimum value (as shown in the maple help page of this plot).

However, when I do this a black square appears (or red if I add colorstyle=HUE). I have tried a lot of things and none seemed to work.

I would also like to be able to draw the isotherms on the plot but that is secondary.

 

I am pretty new to Maple. I have studied the most basic things but don't really understand the whole complexity of this program. Thanks a lot in advance and forgive my faulty english,

Enrique

Page 1 of 1