luigidavinci

65 Reputation

6 Badges

12 years, 340 days

MaplePrimes Activity


These are replies submitted by luigidavinci

@luigidavinci 

 

 I found I can use (don't know if it's the best programming practice for this need)

for i from 1 to 3 do U:=A||i+op(U); end do;

Still, is there a way to make `add` work ? I read `add` is sometimes more efficient than `for`loops.

Also, can I define a new type so that my "matrices" and its algebra can be treated separately than that of the regular `Matrix` type? I'm not sure how to do this since there would be no real difference between my special matrices and any other one of type `Matrix`.

 

Cheers.

Thanks Joe!

I have made some straightforward modifications to handle things like (2*A-At)(V1), where `*` is also redefined. However, when I wanted to use the Maple function add to generate a particular sum of procedures, I get an unevaluated sum again, just as if `add` didn't know about the new definition of `+`. Anyways, I thought I could replace the `add` usage with a `for` loop, but I was wrong, a `for` loop like this:

for i from 1 to 3 do U:=A||i+U; end do;

results in a recursive procedure U. So, what can I do to produce sums like that ?, I thought of generating a string like s:="A1+A2+A3" using `for` loops and then parsing it like U:=parse(s), it sure works but it's not a nice nor a versatil way of doing it. Any suggestions?

Thanks Joe!

I have made some straightforward modifications to handle things like (2*A-At)(V1), where `*` is also redefined. However, when I wanted to use the Maple function add to generate a particular sum of procedures, I get an unevaluated sum again, just as if `add` didn't know about the new definition of `+`. Anyways, I thought I could replace the `add` usage with a `for` loop, but I was wrong, a `for` loop like this:

for i from 1 to 3 do U:=A||i+U; end do;

results in a recursive procedure U. So, what can I do to produce sums like that ?, I thought of generating a string like s:="A1+A2+A3" using `for` loops and then parsing it like U:=parse(s), it sure works but it's not a nice nor a versatil way of doing it. Any suggestions?

>NewAdd := module() option package;  export `+`,`*`;
    `+` := proc(a::array, b::array) option overload;
        array([[a[1,1]],[a[2,1]+b[2,1]]])
    end proc;
   end;
> A:=proc(v::array) array([[v[1,1]-1],[v[2,1]]]); end proc;
> At:=proc(v::array) array([[v[1,1]+1],[v[2,1]]]); end proc;
> with(NewAdd);
> V1:=array([[a],[b]]); V2:=array([[c],[d]]);
> A(V1)+At(V1);  # Good !!
> (A+At)(V1);     # Not Good !

1 2 Page 2 of 2