## Problems in plotting a function of two variables

``````Clear("Global`*")

a = Re(Sqrt(x^2 - 2 x y + y^2 - 1^2));
``````

You cannot take the derivative of a function which contains `Re`. Use `ComplexExpand` to avoid use of `Re`

``````mat = {{0, -a/Sqrt((x - y)^2 + Abs(a)^2)}, {(x - y)/
Sqrt((x - y)^2 + Abs(a)^2), 0}} //
ComplexExpand(#, TargetFunctions -> {Re, Im}) & // Simplify;

d1 = D(mat, x);
d2 = Simplify(mat . d1, {x >= 0, y >= 0});
fun(x_, y_) = Simplify(
Tr(d1 . d1) + (1/Det(mat)) Tr(d2 . d2),
{x >= 0, y >= 0});

Plot3D(
fun(x, y), {x, 0, 5}, {y, 0, 5},
PlotPoints -> 75,
MaxRecursion -> 5,
ClippingStyle -> None) // Quiet
``````

## plotting – No plot generated for this function

The function `fun(x,y)` defined below is not plotted for some reason. Is there a way to fix it and generate a plot?

``````fun(x_, y_) = ((x -
y)^4 (Sqrt(-1 + x^2 - 2 x y + y^2)
Re(Sqrt(-1 + x^2 - 2 x y + y^2)) - (x - y)^2 Derivative(1)(
Re)(Sqrt(-1 + x^2 - 2 x y + y^2)) +
Re(Sqrt(-1 + x^2 - 2 x y + y^2))^2 (-1 +
Derivative(1)(Abs)(
Re(Sqrt(-1 + x^2 - 2 x y + y^2)))) Derivative(1)(Re)(
Sqrt(-1 + x^2 - 2 x y + y^2)))^2 +
Re(Sqrt(-1 + x^2 - 2 x y +
y^2))^4 (Sqrt(-1 + x^2 - 2 x y + y^2)
Re(Sqrt(-1 + x^2 - 2 x y + y^2)) - (x - y)^2 Derivative(1)(
Abs)(Re(Sqrt(-1 + x^2 - 2 x y + y^2))) Derivative(1)(Re)(
Sqrt(-1 + x^2 - 2 x y + y^2)))^2 +
8 (x - y)^2 Re(
Sqrt(-1 + x^2 - 2 x y + y^2))^2 ((x - y)^2 +
Re(Sqrt(-1 + x^2 - 2 x y +
y^2))^2) (-Sqrt(-1 + x^2 - 2 x y + y^2) Re(
Sqrt(-1 + x^2 - 2 x y + y^2)) + (x - y)^2 Derivative(1)(Re)(
Sqrt(-1 + x^2 - 2 x y + y^2)) -
Re(Sqrt(-1 + x^2 - 2 x y + y^2))^2 (-1 +
Derivative(1)(Abs)(
Re(Sqrt(-1 + x^2 - 2 x y + y^2)))) Derivative(1)(Re)(
Sqrt(-1 + x^2 - 2 x y + y^2))) (-Sqrt(-1 + x^2 - 2 x y +
y^2) Re(
Sqrt(-1 + x^2 - 2 x y + y^2)) + (x - y)^2 Derivative(1)(
Abs)(Re(Sqrt(-1 + x^2 - 2 x y + y^2))) Derivative(1)(Re)(
Sqrt(-1 + x^2 - 2 x y + y^2))))/(4 (x - y) (-1 + x^2 -
2 x y + y^2) Re(
Sqrt(-1 + x^2 - 2 x y + y^2)) ((x - y)^2 +
Re(Sqrt(-1 + x^2 - 2 x y + y^2))^2)^4);

Plot3D(fun(x, y), {x, 0, 5}, {y, 0, 5})
``````

## python – mocking a function that runs in a different thread

I have a reactor class that when started, runs in it’s own thread (the thread is being created in the inner implementation of the class which I’m not familiar with).

This class’ instance, in some scenarios calls the function `bla`

Now I want to write unit-tests for this class.

I’ve mocked `bla`, and in my test case, I’m calling this class relevant function and then, the problem is, that when I `blaMock.assert_called_once()` I’m getting an exception because the function was not called.

illustration code:

``````@mock.patch("reactor.reactor.bla")
def test_bla_being_called(self, blaMock):
r = self._get_instance()
r.run_until_complete()  # inside start a thread is being spawned and `bla` is called inside of that thread
blaMock.assert_called_once() # exception, called 0 times.
``````

So it seems like the mock doesn’t hold when the mock-target runs in different thread – is this really the case? is there a workaround for allowing mocking if objects being used in different thread than the one runs the tests?

Using Python 3.6

## worksheet function – Sync data in 2 excels sheets with dynamic data in it

I am working on some metrics and reports where I see I have 2 excel sheets which has partly similar data. Instead of manually updating both the both, I am trying to sync the common details between the 2 sheets while each of them having their independent details.

1st sheet has details as below:

Client Name, Data, PM Name, Hours, Status

2nd Sheet as below:

Client Name, Data, PM Name, Milestone 1 Commence Date, Milestone 1 Completion Date, KPI status

Since the first 3 columns are same, Can that be taken as a reference to sync the data to 2nd sheet, while manually adding the the other details on Sheet 1 and 2?

Also Pls note, the data of first 3 columns in Sheet one keeps changing every day. There might be new rows included in between.

I have used the “Get Data” Option to sync the data between the sheets, However when new rows gets added in between the data doesn’t get aligned properly. Pls let me know if there is any other option that can be used.

## variable definitions – Proper way to construct a function that takes too long to plot and integrate

Consider the functions `phi(t_)` and `psi(t_)` defined in the code below. These are used as basis functions for interpolation purposes. Consider a “time” variable `T`, a total number of interpolation nodes `n0` and a step `h0`. Consider the values at nodes given by variables `a` and `b`. The required interpolation is defined by the function `q(t_)` defined below as the sum of `a` times `phi` plus `b` times `psi`.

``````phi(t_) := Boole(-1 <= t <= 1) (1 - Abs(t))^2 (1 + 2 Abs(t));
psi(t_) := Boole(-1 <= t <= 1) t (1 - Abs(t))^2;
T = N@Pi
n0 = 500;
h0 = T/n0;
a = Table(Cos(i*h0), {i, 0, n0});
b = Table(Sin(i*h0), {i, 0, n0});
q(t_) = Sum(a((k + 1))*phi(t/h0 - k) + h0*b((k + 1))*psi(t/h0 - k), {k, 0, n0});
``````

When constructing the interpolated function `q(t_)` in this kind of manner results in operations on `q(t_)` taking way too long. A simple plot for example

``````AbsoluteTiming(Plot(q(t), {t, 0, T}))
``````

takes more than 4 seconds to compute in my machine. Integrating this function with

``````NIntegrate(q(t), {t, 0, Pi/2})
``````

sends the message

``````NIntegrate`SymbolicPiecewiseSubdivision::maxpwc: The number of piecewise regions has exceeded the maximum value specified by the option MaxPiecewiseCases -> 100. The integration will continue with no piecewise subdivision.
``````

I can get around the integration issue by reducing the number of interpolation nodes to no more than 200, however, this begs the question of whether or not I am doing this the right way. Is there a better way to construct the `q(t_)` function?

Note that I cannot define `q(t_)` in the “set delayed” way because my `a` and `b` coefficients are constantly changing to approach other functions, and I need to store every interpolated function separately.

## purescript – Pass polymorphic record to foreign function

I have `r1` and `r2` record types and I need to pass either `r1` or `r2` to a foreign function (it can handle either r1 or r2 record structure) is it possible to do this (I thought maybe via conversion to Foreign Object)?

Or do I need to declare two different foreign imports pointing to the same functions for this?

## google sheets – How to stop IFS function always giving the same result for x even if greater than x or less than x

The order of your `IFS` needs to be changed.

How the `IFS` function work:

Evaluates multiple conditions and returns a value that corresponds to the first true condition.

In your formula, since your second condition is `C9>=5,"15%"` everything greater than 5 will give a `15%` result. After that, the formula stops checking the following conditions.

Try the following:

``=IFS( C9>=40, "40%",C9>=15, "25%",C9>=5,"15%",C9<5, "0%")``

## Marginal probability density function for each \$X_j\$

Let $$X_!, ldots , X_n$$ i.i.d with $$X_1sim text{Exp}(5theta)$$. For the statistical distribution of $$theta$$ the a priori belief is described by $$text{Gamma}(alpha,1)$$, where $$a$$ a positive parameter.

1. Find the Marginal probability density function for each $$X_j$$.

2. Find the estimator for $$theta$$ according to Bayes considering the square loss function.

For the first question we have to calculate the integral $$f_{X_j}(x_j)=int_0^{infty}f_{x_1ldots x_n}(x_1, ldots , x_n), dx_1, ldots dx_{j-1} dx_{j+1}ldots dx_n$$ or not?

So first we have to find the function $$f_{x_1ldots x_n}(x_1, ldots , x_n)$$.

Knowing that $$X_1sim text{Exp}(5theta)$$ does the following hold?
$$f_{X_1}(x_1mid 5theta)=begin{cases}5theta e^{-5theta x_1} & text{ for } x> 0 \ 0 & text{ for } xleq 0end{cases}$$

## mysql – multiple count and use subsctract function in one query

I try to do more advance query in mysql but got error in query, i try to count and group by. here is my query:

``````"select department,
(select count(id) from mcu group by dept) as tot1,
(select count(status_mcu) from mcu where status_mcu='done' group by dept) as tot2,
(tot1 - sum(select count(status_mcu) where status_mcu='done') as tot3,
FROM mcu"
``````

can you help me out ? what wrong with my query ? i do some search in other threads and this is what i got. try do query like :

``````"select department,
select count(id),
sum(case when status_mcu='done' then 1 end)
...
"
``````

not worked too. Any help is appreciate.

## calculus – weird finding function from the graph

The graph is on the interval (-3,3), defined on R

This function maintain the pattern on all of R

How to find the $$f(x)$$?

See how the graph goes parallel at certain intervals. I am thinking adding one more variables to indicate one of the direction. However, I cannot merge the two together.

Any thoughts?