I have u0 as step function (piecewise definition):
piecewise([0 < t, 1], [t < 0, 0])
Now I compute:
int(u0(t)|t=k, k=-infinity..t)
which gives
piecewise([0 < t, t], [t <= 0, 0])
In a textbook I found the answer:
piecewise([0 =< t, t], [t < 0, 0])
Is this a bug in MuPAD?
I does not matter if you use f(t)=t or f(t)=0 for t=0. In both cases the result is 0
Related
The quiz I met first gave me an Logistic model:
And ask me to linearize it, then evaluate the value of a and k according to the data it gave( in this subject L is took as 3000). I finished that, but got into trouble in the second subject which asked me to do a non-linear-regression with a and k's value evaluated in the first subject. Here's my code:
function y = func(const, t)
y = const(1)./(1 + const(2)*exp(-const(3)*t));
end
t = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12];
y = [43.65, 109.86, 187.21, 312.67, 496.58, 707.65 , ...
960.25, 1238.75, 1560, 1824.29, 2199, 2438.89, 2737.71];
yAss = log ((3000 ./ y) - 1);
p = polyfit (t, yAss, 1);
a = exp (1) ^ (p(2));
k = -p(1);
beta0 = [3000, a, k];
beta = nlinfit (t, yAss, #func, beta0);
yAfter = beta(1) ./ (1 + beta(2) * exp (-beta(3) * t));
yCompare = 3000 ./ (1 + a * exp (-k * t));
scatter (t, y); hold on;
plot (t, yAfter, 'r');
plot (t, yCompare);
And what it gave:
The red curve is generated with the value returned by nlinfit, Anyone could tell me what is wrong?
I feel stupid... Answering my own question and the question itself is stupid either...
beta = nlinfit (t, yAss, #func, beta0);
should be:
beta = nlinfit (t, y, #func, beta0);
I really want to delete that question...
I want to perform some symbolic computation with the discrete-time unit step function, which I cannot seem to find a built-in definition of. I've tried heaviside(n + 0.5) and also sym('piecewise([n < 0 , 0], [n >= 0, 1])'). Here is some sample code:
syms n k
unitStep = #(n) subs(sym('piecewise([k < 0 , 0], [k >= 0, 1])'), n);
x1 = #(n) unitStep(n);
h1 = #(n) 2 .^ (-n) .* unitStep(n);
y1 = #(n) symsum(x1(k) .* h1(n - k), k, -inf, inf);
simplify(y1(n))
Which gives the output
piecewise([in(n, 'real'), symsum(piecewise([n < k, 0], [k <= n, 2^(k - n)]), k, 0, Inf)])
(Not at all helpful) I cannot seem to get satisfactory results whatever I do. Anyone have tips for evaluating symbolic sums with the unit step function in them? I do not want to use heaviside(n) because heaviside(0) evaluates to 0.5.
I’m trying to formulate and solve a linear programming problem using the spicy.optimize.linprog function.
I want to solve the function Ax = b subject to the following constraints:
# A b
-0.4866 x1 + 0.1632 x2 < 0
0.3211 x1 + 0.5485 x2 < 0
-0.5670 x1 + 0.1099 x2 < 0
-0.1070 x1 + 0.0545 x2 = 1
-0.4379 x1 + 0.1465 x2 < 0
0.0220 x1 + 0.7960 x2 < 0
-0.3673 x1 - 0.0494 x2 < 0
I have as input an nx2 matrix A and nx1 matrix b. The result should be the vectors x1 and x2. Here's my input data.
# Coefficients
A = [[-0.4866, 0.1632],
[0.3211, 0.5485],
[-0.5670, 0.1099],
[-0.1070, 0.0545],
[-0.4379, 0.1465],
[0.0220, 0.7960],
[-0.3673, -0.0494]]
# Inequalities
b = [0, 0, 0, -1, 0, 0, 0]
I think my problem is how to formulate c, the function the be minimized for input into the linprog function.
res = linprog(c, A, b)
I'm able to solve for the upper bounds by:
c = [1, 0, 0]
A = [[-1, -0.486, 0.1632],
[-1, 0.3211, 0.5485],
[-1, -0.5670, 0.1099],
[-1, -0.1070, 0.0545],
[-1, -0.4379, 0.1465],
[-1, 0.220, 0.7960],
[-1,-0.3673, -0.0494]]
b = [0, 0, 0, -1, 0, 0, 0]
c0_bounds = (0, 1)
x1_bounds = (-np.inf, np.inf)
x2_bounds = (-np.inf, np.inf)
res = linprog(c, A_ub=A, b_ub=b, bounds=(c0_bounds, x1_bounds, x2_bounds), options={"disp": True})
But now what if I also want to solve for the lower bounds?
I have range from 0 to a which I have to proportionally map to a range from b to c. How to achieve this in NetLogo.
0 to a -> b to c
[0 a] -> [b c]
assuming your input is x, then:
b + (x / a) * (c - b)
I want to simplify the following operation, but it yields me an error that says: too many input arguments. Can anybody tell me what am i doing wrong???
>>
syms a b c d e f g h i j k l x y xy
A=[1 a b a^2 a*b b^2; 1 c d c*2 c*d d^2; 1 e f e^2 e*f f^2; 1 g h g^2 g*h h^2; 1 i j i^2 i*j j^2; 1 k l k^2 k*l l^2]
B=[1; 0; 0; 0; 0; 0]
A =
[ 1, a, b, a^2, a*b, b^2]
[ 1, c, d, 2*c, c*d, d^2]
[ 1, e, f, e^2, e*f, f^2]
[ 1, g, h, g^2, g*h, h^2]
[ 1, i, j, i^2, i*j, j^2]
[ 1, k, l, k^2, k*l, l^2]
B =
1
0
0
0
0
0
>> simplify(inv(A)*B, 'steps', 100)enter code here
I've put the code you pasted in my copy of matlab (R2013a) and it finishes without any errors. The result is not simplified very much though.
If your computer is choking on the computation (it is very long), you could try separating the things a bit and see if it helps.
vec=inv(A)*B
for n=1:6
results(n)=simplify(vec(n), 'steps', 100);
end
results
Your call belongs to this MATLAB function:
But it is in Symbolic Math Toolbox, which means it can only simplify math formulas instead of complex matrix computation.
Simplify Favoring Real Numbers
To force simplify favor real values over complex values, set the value of Criterion to preferReal:
syms x
f = (exp(x + exp(-x*i)/2 - exp(x*i)/2)*i)/2 - (exp(- x - exp(-x*i)/2 + exp(x*i)/2)*i)/2;
simplify(f, 'Criterion','preferReal', 'Steps', 100)
ans =
cos(sin(x))*sinh(x)*i + sin(sin(x))*cosh(x)
If x is a real value, then this form of expression explicitly shows the real and imaginary parts.
Although the result returned by simplify with the default setting for Criterion is shorter, here the complex value is a parameter of the sine function:
simplify(f, 'Steps', 100)
ans =
sin(x*i + sin(x))
Instead, I think you could try use this function:
Simplify(f, Steps = numberOfSteps)
But first of all, you need a 'f' which could be used like a recursion or iteration function.
e.g. Simplify(sin(x)^2 + cos(x)^2, All)
Hope this helps!