## 183 Reputation

16 years, 103 days

## thanks...

Thanks Carl. Your solution works in both versions of Maple.

## Thanks to everyone for your input...

Thanks for confirming the effect and thanks to everyone else for your input.

My setup is Maple 2015 on 32bit Win7. I was shutting down the Maple session between runs. Running the tests again gave somewhat different results but still with the same effect. This may be due to the fact that I had another and different worksheet open (but not running) when I did the original tests.

This effect is surprising since I wrongly assumed that the memory usage wouldn't change with n since the variables are always overwritten in the procedures. The results suggest that the values of y and yi for different i are being stored (at least for a while) as the procedure is called continuously.

I modified the program to do a gc() inside the loop and this keeps the memory under control, although the run time soars.

Since my real code has memory problems after many loops, I'll try a periodic gc() to see if this helps, although the help system discourages calling gc().

Markiyan Hirnyk: I don't really need these integrals. It was just an example to show the effect I was getting with my real code that involves a lot of integrations in a loop with a procedure used to calculate the integral terms.

Thanks all.

## From Maple worksheet stats...

I read the test code into a Maple worksheet and run it. The memory figures are what Maple reports on the bottom right corner of the worksheet (along with the run time).

Thanks.

## Yours is better...

Sigh. It looks like we both had the same idea. Yours is a more elegant solution.

We may be able to help if you provide some basic information. What is the mathematical formulation of your problem?

## Strange that [] is needed here...

Thanks Carl.

However I find it strange that [] is needed here since we are just reading one value at a time in rather than making a list, unless I'm missing something.

## Syntax for fscanf line...

Where is the effect of the [] in the line A[i,j]:=fscanf( fname, "%a")[]: documented?

I see that if I leave it out the terms have extra [] around them.

Thanks.

## thanks...

Thanks Acer and Tom. Tom's solution is what I need.

## Thanks...

Thanks for your two alternate suggestions.

## Great...

Great. This will avoid accidental errors.

Thanks again.

## Agreed...

I will avoid L(x*f(x)) and use a nonlinear N(x*f(x)) in this case. It would be good if you could use something like a "a::name except x" syntax in the definition of L to avoid accidental mistakes.

Thanks.

## This works...

To answer my own question, this works.

define(L,orderless,multilinear,
L(a::name*b::function,c::function) = a*L(b,c),
L(a::name*b::function,c::name*d::function) = a*c*L(b,d)
);

val:=L(c*y1(x)+d*y2(x), e*z1(x)+f*z2(x));
diff(val,c);

## Works but a bit restrictive...

The constant command works but then c..f can't be treated as variables. So the following gives an error in the diff command while the expansion is ok.

constants:=constants,c,d,e,f;
val:=L(c*y1(x)+d*y2(x), e*z1(x)+f*z2(x));
diff(val,c);

Presumably c..f need to be allowed to vary.

Thanks.

## Thanks but only works for numbers...

Thanks Carl.

However,

L(c*y1(x)+d*y2(x), e*z1(x)+f*z2(x));

with c to f as algebraic doesn't expand.

## excellent explanation...

Thanks for the great exaplanation. It helps to learn new commands and how they work.

I didn't know about the selectremove command and was using a clumsy loop with an if assigned test.

 1 2 3 4 5 Page 3 of 5
﻿