Joe Riel

9530 Reputation

23 Badges

20 years, 26 days

MaplePrimes Activity


These are answers submitted by Joe Riel

To read from an Excel spreadsheet, use ?ExcelTools[Import].  There are multiple ways to read from a text file; start with ?readdata.

The ?odeplot procedure does not work with that expression; it requires that the expression can be fully evaluated at time t. Following is a method to do this, using a simple example

deq := diff(x(t),t) + x(t) = 1:
dsol := dsolve({deq, x(0)=0},numeric,output=listprocedure);
xt := eval(x(t), dsol);
Xt := t -> evalf(Int(xt,t..t+tau));
tau := 1:
plot([xt,Xt], 0..1);

There are a lot of problems with that modelica.  I can clean some up, but others are more substantial.  From a practical point, the real problem is that the template code (I assume you are using the Custom Modelica Component template) is suppressing a useful error messag returned by the flattener (code that parses the Modelica).  I'll be fixing that bug.  In the meantime I'm going to explain a workaround so that you can see the error messages.

Save your modelica to a file (say basisFunction.mo).

In Maple, assign the following procedure

flatten := proc( modelica :: string, model :: string )
uses MM=MapleSim:-Modelica;
    MM:-PrintResult(MM:-Flatten(modelica,model));
end proc:

Now call the procedure, passing it the name of the saved Modelica file and the Modelica class of interest

flatten("basisFunction.mo", "basisFunction");
Error, (in MapleSim:-Modelica:-EvaluateExpression) cannot resolve
`basisFunction.theta_r[1,1]`; there is no `theta_r[1,1]` in model
`basisFunction`

I've included a typical error message.  The error is a bit cryptic, but the reason for it is that the declaration of theta_r does not include dimensions.  Actually, for that parameter there is another issue. linsolve returns a vector (one dimensional) but you are accessing theta_r with two dimensions.  You'll have to resolve that. 

Other problems include bPen being declared twice, parameters c and bFunc being given no initial value (actually, your code is assigning to parameters, which is not allowed, it should be a variable).  

Let me know if that allows you to resolve the bugs.



You could try a ?piecewise expression:

piecewise( h(t)>0, 0, F(h(t))) 

where F(h(t)) is an expression for the force during compression

Remove the embedded graph from the spreadsheet; that, apparently, is interfering with the import of the Matrix.

 

The integrand has the opposite parity of n, so the integral is zero for n even.

The declarations of x1 and x2 don't make sense.  The left part should be a Modelica type; what you have is referencing a variable in the class.  I'm not quite sure what you intend. If you want two real inputs, one for angle, one for angular velocity, just do

Modelica.Blocks.Interfaces.RealInput phi annotation(...);
Modelica.Blocks.Interfaces.RealInput omega annotation(...);

and use phi and omega where you have x1 and x2 (or rename the inputs to x1 and x2). Alternatively, if you want a rotational flange as a connection and will sense phi and omega from it, you could do

Modelica.Mechanics.Rotational.Interfaces.Flange_a  flange_a annotation(...);
Real phi, omega;
equation
phi = flange_a.phi;
omega = der(phi);
...

Create a Random Data template, select the desired distribution (Gaussian), fill in the parameters, select the number of points and simulation time, then click the Generate Random Data button.  That attaches a worksheet to your document with the data.  To use, insert a Time Lookup Table block (Signal Blocks --> Interpolation Tables --> Time Lookup and connect the output signal to whatever is desired.

I assume you meant a Time Lookup table.  Use the same data (spreadsheet or csv file) in a 1D interpolation table and connect its input to a sawtooth generator ( Signal Blocks --> Sources --> Real --> Saw Tooth ), with amplitude = T = 20.

What frequently works is to use Ctrl-/, which returns the cursor to the baseline.  You won't want to do that if you are inserting a superscript in an expression that is not on the baseline.  The advantage of Ctrl-/ is that it can be typed without leaving the home row (at least if you've configured your keyboard to make the Ctrl key readily accessible).

I wish that there were another binding for the right-arrow function that uses a more convenient key.

One way (not ideal, but easy to enter)

N := 15:
L := LinearAlgebra[RandomVector](N):

member(min(L),L,'i');
i;

A ZOH block takes two parameter, the sampling interval and the start of the samplilng.  The sampling interval is fixed by your discrete system, it should match that.

Why not use the triggered sampler (in Signal Blocks -> Discrete).

 

The `and` should not be in there.  Is that supposed to be an algebraic constraint?  If so then the system is over-determined.

?plots[odeplot] can handle this.

S:=0.79*cos(t)+0.3*sin(t);
DGL1 := 20*(D(D(x)))(t)+10*(D(x))(t)+2500*x(t)+300 = S;
init := x(1.2) = 0, (D(x))(1.2) = 10.63081252;
F := dsolve({DGL1, init}, numeric):

plots:-odeplot(F, [t,x(t)-S], 1.2 .. 2, 'numpoints'=200);

First 39 40 41 42 43 44 45 Last Page 41 of 114