Joe Riel

9530 Reputation

23 Badges

20 years, 24 days

MaplePrimes Activity


These are answers submitted by Joe Riel

That cannot be done.  What are you really trying to accomplish?  

Is this simplified version what you want?

with(VectorCalculus):
vars := [x,y]:
J := Jacobian([x^2*y, x+y], vars);
f := unapply(convert(J,listlist),vars);
CodeGeneration[C](f,optimize,declare = map(`::`,vars, float));
void f (double x, double y, double cgret[2][2])
{
  double t3;
  t3 = x * x;
  cgret[0][0] = 0.2e1 * x * y;
  cgret[0][1] = t3;
  cgret[1][0] = 1;
  cgret[1][1] = 1;
}
 

 

Use the following:

_LatexSmallFractionConstant := 0:
latex(1/2);
{\frac {1}{2}}

That depends somewhat on the form of n.  For example, if n is a numeric fraction, then this is readily solvable. Similarly if x and y are purely symbolic, so one merely has to identify the syntactic form. 

You could use eliminate with a dummy variable (I used the underscore):

eqs := {x-y=0, y-x=0}:
eliminate(eqs, _)[2];
                               {x-y}

Doing so converts the remaining equations to expressions implicitly equal to zero.  

 

The first consideration might be whether the original data should be in a list. An Array, possibly of datatype = float[8], could be a better choice. Depending on what f is, you might be able to use a compiled procedure. Or use evalhf. Also returning a list (from f), then using only one element of it is not ideal. 

Before doing anything, consider using a profiling tool (CodeTools[Profiling]) to determine where most of the time is being spent.  

Did you try the LongestCommonSubstring command in StringTools?

If a is a list or set, a[] is equivalent to op(a), which returns the expression sequence of the list/set, that is, it removes the brackets/braces.

Followup

That doesn't really answer your question about why this works. If you consider that, for single integers i, and L a list or set, op(i,L) = L[i], then a reasonable extension, when i = NULL, is that op(NULL,L) = L[NULL], which is evaluates to op(L) = L[]. The equality fails, however, when i is a range, or list of integers. There is no reason they should be the same for all types of i; it is better to have different, useful, behavior for the two notations.

Note that when i is a list of integers, op returns an element at a specified depth, while, say, L[[3,2,2]] returns a list consisting of [L[3],L[2],L[2]]. That notation, using a list containing a list as the index, is useful for generating a permutation or other arrangement of list, set, expression sequence, or Vector.

 Note that after the for loop, jj is assigned M+1. I'm not sure that is the issue, you didn't provide enough input.

The $ operator is old and mostly deprecated, replaced by seq, which has more useful evaluation rules. An exception is as a repetition operator, for example, x $ 5 evaluates to x,x,x,x,x, where the x is not evaluated. For iterations it is generally better to use seq. 

PDETools[dchange] can be used for this task. You may or may not want to pass it the 'known' parameter, which determines how the functions w and phi are handled. As an example

 

 

PDETools:-dchange({x=X*l,t=T/(k/h)},eq,[X,T],params=[l,k,h]);
PDETools:-dchange({x=X*l,t=T/(k/h)},eq,[X,T],params=[l,k,h],known={phi,w});

There are a few ways you can do that.  The simplest is to click the !!! icon on the toolbar; doing so executes all the input regions in the worksheet.  Another way is to set the input region in which the assignment is located to autoexecute by putting the cursor on the assignment and clicking Format --> Autoexecute --> Set. Another approach, more applicable when assigning a procedure used in the worksheet, is to put the assignment in the startup code region. Do so by clicking the Edit startup code icon on the toolbar, then inserting the assignment in the code edit region that appears, then saving it.

Hard to say without seeing the model.  Note that MapleSim includes an example of a simple bridge rectifier, look in Examples --> Physical Domains --> Electrical --> Diode Bridge Rectifier

Take a look at Examples --> Electrical --> Simple DC Motor with Backlash.  It uses a PI controller to control the speed of a simple motor.

The presence of the x1(t) in the derivative prevents coeff from returning what you want.  You can use ?frontend for this,

frontend(coeff, [E,x1(t)]);
                 3*k

 

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