Why does evaluating an expression in system.time() make variables available in global environment?
Tag : r , By : Antony Briggs
Date : March 29 2020, 07:55 AM
Does that help It is because supplied arguments are evaluated in the evaluation frame of the calling function (as described in Section 4.3.3 of the R Language Definition document). The expression wrapped by the user in system.time() is a supplied argument which gets matched positionally to expr. Then, when expr's evaluation is forced in the body of system.time, it is evaluated in the evaluation frame of the calling function. If system.time() was called from the .GlobalEnv, that is where any assignments that are a part of expr will take place. st2 <- function(expr = newVar <- 33){
expr
}
# Using the default argument -- eval and assignment
# within evaluation frame of the function.
st2()
newVar
Error: object 'newVar' not found
# Using a supplied argument -- eval and assignment
# within the calling function's evaluation frame (here .GlobalEnv)
st2(newVar <- 44)
newVar
# [1] 44
|
Evaluating the performance in time of a specific portion of the matlab code?
Date : March 29 2020, 07:55 AM
I think the issue was by ths following , The most convenient way is to use the GUI profiler tool. You can find it in the dropdown menus (Desktop->Profiler), or you can start it from the command line by typing profile viewer. Then you enter the name of the function at the top of the window, hit "run", and wait till the code is done running. Clicking on the links brings you into the respective function, where you can see runtime line-by-line. Note that timing code that runs very fast and for only a handful of iterations can be tricky; for these cases you may want to use the timeit function from the Matlab File Exchange.
|
Modelica : variables of class during instantiation
Date : March 29 2020, 07:55 AM
will help you First of all Modelica has only one type of object, the class, and the other objects (model, record, package) are only special types of class with restrictions. That means that every object must follow the same rules, therefore I'll refer to the object class, but what I'll write will apply to every Modelica object. The variables are instantiated per object means that if you have a Modelica class like the following one: partial class MySimpleClass
Real variable1;
equation
variable1 = time;
end MySimpleClass;
class mySecondClass
MySimpleClass instanceOfTypeMySimpleClass;
MySimpleClass instanceTwoOfTypeMySimpleClass;
Real variable1;
equation
variable1 = instanceOfTypeMySimpleClass.variable1;
instanceTwoOfTypeMySimpleClass.variable1 = 3;
end mySecondClass;
|
How do I model a single time event in Modelica occurring at a predetermined time?
Date : March 29 2020, 07:55 AM
hop of those help? Your solution is almost fine. Below is your code with a couple modifications. Used if then else can also do if then elseif then elseif then ... else Added balance variable xb to have common derivative equation (not necessary just a coding style). model time_event
Real x(start = 0) "state variable for this example";
parameter Real T_ch = 5 "time at which the system dynamics undergoes a change";
Real xb "Balance variable for derivative";
equation
der(x) = xb;
if time <= T_ch then
xb = x + 1;
else
xb = -x;
end if;
end time_event;
|
Modelica - freezing a specific time value during simulation
Date : March 29 2020, 07:55 AM
should help you out You may find the sample and hold example in my book useful. It uses sampling based on time whereas you probably want it based on your pressure value. But the principle is the same. That will allow you to record the time at which your event occurred. Addressing your specific case, the following (untested) code is probably pretty close to what you want: ...
Modelica.SIunits.Time t_star=-1;
equation
when p >= p_set then
t_star = time;
end when;
A = if t_star<0 then A_max else min(const*(t - t_star) + A_0, A_max);
|