tomleslie

13876 Reputation

20 Badges

15 years, 166 days

MaplePrimes Activity


These are replies submitted by tomleslie

All you have told me is that you want to plot a function f() which can be defined as

f(x, t(x))

Given a range of values for x, the funtion t(x) and the function f(x), this is trivial - all you have to do is define the relevant functions.

Pretty trivial to create a Matrix with (implied) nested for loops - as in, simple example

Matrix(5,5, (i,j)-> i^2+I*i*j);

No idea what you want to plot though - more info required!

The closest I got to what you want is (with your example)

t := sin(1);
lbl:=θ__1=parse(sprintf("%5.3f", t));

Closest I got to what you want is (with your example)

t := sin(1);
lbl:=θ__1=parse(sprintf("%5.3f", t));

what you do with lbl at this point is up to you!

If I run te basic example from the eBookTools help, ie

with(eBookTools):
book := NewBook("eBookSample", "eBook Sample Book", "Maplesoft, a division of Waterloo Maple Inc.", "2012"):
AddChapter(book, "legal", cat(kernelopts('datadir'), "/eBookTools/Legal.mw")):
AddChapter(book, "preface", cat(kernelopts('datadir'), "/eBookTools/Preface.mw")):
AddChapter(book, 1, cat(kernelopts('datadir'), "/eBookTools/GettingStartedWithMaple.mw")):
CreatePDF(book);

Then this creates a pretty complicated pdf file from the three specified **.mw files. These include lots of tables - so what exactly is going wrong

   restart;
   a1 := Matrix(3, 4, [1, 2, 3, 4, 7, 8, 9, 10, 13, 14, 15, 16]):
   a2 := Matrix(3, 2, [5, 6, 11, 12, 17, 18]):
   a3 := Matrix(2, [19, 20, 25, 26]):
   a4 := Matrix(2, 4, [21, 22, 23, 24, 27, 28, 29, 30]):
#
# Somewhat surprised dagger-bracket concatenation
# works, particularly in view of the help page
#
# ?Matrix and Vector Construction Shortcuts
#
# which never even mentions concatenating matrices
# (just scalars and row/column vectors)
#
   < <a1|a2>, <a3|a4> >;
#
# Particularly annoying then, that this doesn't
# (cos it was my first thought!!)
#
   Matrix(5,6,[[a1,a2],[a3,a4]]);                              
#
# The following is neater than my previous
# solution and should have been obvious -
# but wasn't :-(
#
   with(ArrayTools):
   Concatenate(1, Concatenate(2,a1,a2),
                          Concatenate(2,a3,a4)
                     );

With the set of data you now aupply, ie

a1 := Matrix(3, 4, [1, 2, 3, 4, 7, 8, 9, 10, 13, 14, 15, 16]);
a2 := Matrix(3, 2, [5, 6, 11, 12, 17, 18]);
a3 := Matrix(2, [19, 20, 25, 26]);
a2 := Matrix(3, 2, [5, 6, 11, 12, 17, 18]);

where do you get the entries 21, 22, 23, 24, 27, 28, 29, 30 in your final matrix?

I'm going to assume that your data should be

a1 := Matrix(3, 4, [1, 2, 3, 4, 7, 8, 9, 10, 13, 14, 15, 16]):
a2 := Matrix(3, 2, [5, 6, 11, 12, 17, 18]):
a3 := Matrix(2, [19, 20, 25, 26]):
a4 := Matrix(2, 4, [21, 22, 23, 24, 27, 28, 29, 30]):

This can be  inserted into a final matrix (in the way I think that you want!) using

r:=a->op(1,a)[1];
c:=a->op(1,a)[2];
A := Matrix(r(a1)+r(a3), c(a1)+c(a2)):
A[1..r(a1), 1..c(a1)]:=a1;
A[1..r(a2), c(a1)+1..c(a1)+c(a2)]:=a2;
A[r(a1)+1..r(a1)+r(a3), 1..c(a3)]:=a3;
A[r(a2)+1..r(a2)+r(a4), c(a3)+1..c(a3)+c(a4)]:=a4;

@um_vue 

Your original Matrix definitions were

a1 := Matrix(3, [1, 2, 3, 7, 8, 9, 13, 14, 15]);
a2 := Matrix(3, 2, [5, 6, 11, 12, 17, 18]);
a3 := Matrix(2, [19, 20, 25, 26]);
a2 := Matrix(3, 2, [5, 6, 11, 12, 17, 18]);

and the output you want is

In this output matrix, where did the entries 4, 10, 16, 27, 28, 29, 30 come from - they don't exist anywhere in your input.

Also, as Carl has noted

Clearly you want a matrix whose entries are matrices rather than a block matrix because your sizes won't fit into a block matrix.

which is why we both went for a matrix whose entries are themselves matrices - this is the only way your original question makes sense

When you reimport from Excel dat will probably be Array/Matrix, so best to use 'parse' in an elementwise way, as in

parse~(Matrix( [["1/2", "2/3"],["3/4", "4/5"]]));
parse~(Array(  [["1/2", "2/3"],["3/4", "4/5"]]));

The following worksheet (without the output=Array() stuff) would seem to provide the same output as your original code

WhtCorr.mw

I don't really understand the comment

"Some complained that the graphs do not satisfy the boundary conditions smoothly."

so if you want a response to this part you will have to clarify

 

With your original code


for n=1:10
     ist(n) = n+1;
end

So the above for loop will create a list of size 9, with objects being number 2 through 11.

First of all this wont create a list, ut even in pseudocode terms the lsit woul have been of size 10!!

If you really wnat to create a list like this in Maple then

[seq( j+1, j=1..10)]

will work.

Now you make the statement

 I want the list to be in {} form

Doesn't make any sense unless you want a set rather than a list: if you want a set rather than a list then ignore the above and instead use

{seq( j+1, j=1..10)}

Trivail to use expressions, as in

e1 := a^2 + b;
e2 := b + a*b;
e3:= b*a + a*b^2;
{seq( e||j, j=1..3)};

If you are tryign to differentiate the function f|(x) wrt x then

diff(f(x),x)

is the standard way to do it and is pretty bulletproof

If you really want to compute the derivative as

     (           f(x+h)-f(x) )
lim( h->0,  ------------  )
     (                  h        )

then the procedure

normaldiff:= proc( f1 )
                            return limit
                                      (  ( subs
                                            ( x=x+h, f1 )
                                            -
                                            f1
                                        )
                                        /
                                         h,
                                        h=0
                                     );
                     end proc;

will work for most functions.

If I look at your original code there  are so many syntax problema that I cannot figure out what else you might be trying to achieve - see the comments on your original code below

normaldiff := proc(f1)    ### this proc starts but never ends - no end proc statement anywhere
return limit((subs(x=x+h,f1)-f1)/h, h=0):
end if:                          ### this if statement ends but has never started wtf??
recurdiff := proc(f2)      ### this proc starts but never ends - no end proc statement anywhere
if f2 = 0 then
return 0:
end if:
if f2 <> 0 then
return limit((subs(x=x+h,normaldiff(f2)+recurdiff(f2))-(normaldiff(f2)+recurdiff(f2)))/h, h=0):
end if:

f := x;
normaldiff(f)+recurdiff(f);

First of all, Preben's solution is entirely correct.

It may be illuminating to consider that a parametric plot is defined by providing a list to the plot command, such as

plot( [ xcoordinate_As_A_Function_Of(t),
          ycoordinate_As_A_Function_Of(t),
          range_Of_t
       ]
     );

In general it is always possible to produce more than one plot from a single plot() command, by supplying the individual plots as a list. So in the case of parametric plots, one ends up with a list of lists as Preben did

plot( [
          [ xcoordinate_As_Function1_Of(t),
            ycoordinate_As_Function1_Of(t),
            range1_Of_t
          ],
          [ xcoordinate_As_Function2_Of(t),
            ycoordinate_As_Function2_Of(t),
            range2_Of_t
          ]
       ]
);

An alternative (which is occasionally easier to debug) is to define two entirely separate plot structures, and display them in the same plot, using

p1:=plot( [ xcoordinate_As_Function1_Of(t),
                 ycoordinate_As_Function1_Of(t),
                 range1_Of_t
               ]
             );
p2:=plot( [ xcoordinate_As_Function2_Of(t),
                 ycoordinate_As_Function2_Of(t),
                 range2_Of_t
               ]
             );
with(plots);
display( [p1, p2] );

@Maliha Saleem 

If I just write your last two commands in 1-D math (and comment out the 2D versions) then they execute with no error

fixerror.mw

So the problem would seem to be with the 2-D parser. Like Preben I only ever use 1-D input.

I'm pretty sure that the answers are not what you want although having read your worksheet a couple of times, I cannot figure out what you are trying to achieve

Have to agree with Preben, at least in Maple2015.1, and 18.02

Somewhat puzzled as to why you might want this construct. I can think of a couple of possibilities, but they are obscure. I need some context, so please upload worksheet using the big green up-arrow

First 179 180 181 182 183 184 185 Last Page 181 of 207