complex – Symbolic expression of group delay

So I’m trying to find the symbolic expression of the group delay of this complex function:

TFilter=(K1 wp1^2)/(-w^2 + (i*w*wp1)/Q1 + wp1^2)

My attempt was to first find the real and imaginary parts of these function. However when I do:

Re(TFilter)

It just returns Re((K1 wp1^2)/(-w^2 + (iwwp1)/Q1 + wp1^2)) without solving it…

How do I correct this?

complex – How to specify that symbolic expressions are real numbers in Mathematica?

I have the following complex expression

TFilter=-((K1 w^2 wp1^2)/((w^2 wp1^2)/Q1^2+(-w^2+wp1^2)^2))-(I K1 w wp1^3)/(Q1 ((w^2 wp1^2)/Q1^2+(-w^2+wp1^2)^2))+(K1 wp1^4)/((w^2 wp1^2)/Q1^2+(-w^2+wp1^2)^2)

I want to take the real part of it. However when I do Re(TFilter) the output is:

Im((K1 w wp1^3)/(Q1 ((w^2 wp1^2)/Q1^2 + (-w^2 + wp1^2)^2))) + Re(-((K1 w^2 wp1^2)/((w^2 wp1^2)/Q1^2 + (-w^2 + wp1^2)^2)) + (K1 wp1^4)/((w^2 wp1^2)/Q1^2 + (-w^2 + wp1^2)^2))

I guess it’s because Mathematica doesn’t know if the symbolic expressions are real or complex number. How do I “tell” it that? Is there any way to specify?

Solve a complex complex equation

enter image description here

If k = 1, m = 37, z is complex number.
An unusual equation of complex numbers.
You need to find the number of solutions for the given parameters.

Complex Form Builder

Example: https://eab.business.govt.nz/employmentagreementbuilder/application/position

Looking for something that has an admin section that allows users to build new forms without a programmer.

Output to pdf.

Has anyone seen anything like this?

calculus and analysis – Remove complex part of a solution

I have a function intSL(a,zl,zh) where I want to compute its derivative with respect to zl given some values of a and zh. I also want to plot it wrt to zl with the range 0 < zl < 1.

However, there are some zl where my function displays an error message and produces a complex value. When I compare results that are complex valued to the result that are not, it seems like their corresponding real parts has a trend and so I think I could just eliminate the imaginary part (I think???), but I do not know how to do it.

Here is my code,

d = 3;
torootL(a_?NumericQ, t_?NumericQ, zl_?NumericQ, zh_?NumericQ) := a - NIntegrate((zl y^d)/Sqrt((1 - (zl/zh)^(d + 1) y^(d + 1)) (1 + t^2 (1 - (zl/zh)^(d + 1))^-1 - y^(2 d))), {y, 0, 1})
tz(a_?NumericQ, zl_?NumericQ, zh_?NumericQ) := t /. FindRoot(torootL(a, t, zl, zh), {t, 1, -1000, 10000})
intSL(a_?NumericQ, zl_?NumericQ, zh_?NumericQ) := NIntegrate(With({b = zl/zh}, (((-1)/(d - 1)) (zl^(2 d) (1 + tz(a, zl, zh)^2 (1 - (zl/zh)^(d + 1))^(-1)))^(-1) zl^(2 d)) x^d ((1 - (b x)^(d + 1))/(1 - (zl^(2 d) (1 + tz(a, zl, zh)^2 (1 - (zl/zh)^(d + 1))^(-1)))^(-1) (zl x)^(2 d)))^(1/2) - ((b^(d + 1) (d + 1))/(2 (d - 1))) x ((1 - (zl^(2 d) (1 + tz(a, zl, zh)^2 (1 - (zl/zh)^(d + 1))^(-1)))^(-1) (zl x)^(2 d))/(1 - (b x)^(d + 1)))^(1/2) + (b^(d + 1)x)/((1 - (b x)^(d + 1)) (1 - (zl^(2 d) (1 + tz(a, zl, zh)^2 (1 - (zl/zh)^(d + 1))^(-1)))^(-1) (zl x)^(2 d)))^(1/2)), {x, 0, 0.98, 0.99, 1}, MaxRecursion -> 20, PrecisionGoal -> 6)

Here is an example of the evaluation of the derivative,

intSLL(zl_) := Evaluate(D(intSL(0.01, zl, 1), zl))

In(58):= intSLL(0.3)

During evaluation of In(58):= FindRoot::jsing: Encountered a singular Jacobian at the point {t} = {-5.99038*10^-9}. Try perturbing the initial point(s).

During evaluation of In(58):= FindRoot::jsing: Encountered a singular Jacobian at the point {t} = {-5.99038*10^-9}. Try perturbing the initial point(s).

During evaluation of In(58):= FindRoot::jsing: Encountered a singular Jacobian at the point {t} = {-5.99038*10^-9}. Try perturbing the initial point(s).

During evaluation of In(58):= General::stop: Further output of FindRoot::jsing will be suppressed during this calculation.

During evaluation of In(58):= FindRoot::lstol: The line search decreased the step size to within tolerance specified by AccuracyGoal and PrecisionGoal but was unable to find a sufficient decrease in the merit function. You may need more than MachinePrecision digits of working precision to meet these tolerances.

During evaluation of In(58):= FindRoot::lstol: The line search decreased the step size to within tolerance specified by AccuracyGoal and PrecisionGoal but was unable to find a sufficient decrease in the merit function. You may need more than MachinePrecision digits of working precision to meet these tolerances.

During evaluation of In(58):= FindRoot::lstol: The line search decreased the step size to within tolerance specified by AccuracyGoal and PrecisionGoal but was unable to find a sufficient decrease in the merit function. You may need more than MachinePrecision digits of working precision to meet these tolerances.

During evaluation of In(58):= General::stop: Further output of FindRoot::lstol will be suppressed during this calculation.

During evaluation of In(58):= FindRoot::reged: The point {10000.} is at the edge of the search region {-1000.,10000.} in coordinate 1 and the computed search direction points outside the region.

During evaluation of In(58):= FindRoot::reged: The point {10000.} is at the edge of the search region {-1000.,10000.} in coordinate 1 and the computed search direction points outside the region.

During evaluation of In(58):= FindRoot::reged: The point {10000.} is at the edge of the search region {-1000.,10000.} in coordinate 1 and the computed search direction points outside the region.

During evaluation of In(58):= General::stop: Further output of FindRoot::reged will be suppressed during this calculation.

Out(58)= 0.0149288

In(57):= intSLL(0.4)

During evaluation of In(57):= FindRoot::lstol: The line search decreased the step size to within tolerance specified by AccuracyGoal and PrecisionGoal but was unable to find a sufficient decrease in the merit function. You may need more than MachinePrecision digits of working precision to meet these tolerances.

During evaluation of In(57):= FindRoot::lstol: The line search decreased the step size to within tolerance specified by AccuracyGoal and PrecisionGoal but was unable to find a sufficient decrease in the merit function. You may need more than MachinePrecision digits of working precision to meet these tolerances.

During evaluation of In(57):= FindRoot::lstol: The line search decreased the step size to within tolerance specified by AccuracyGoal and PrecisionGoal but was unable to find a sufficient decrease in the merit function. You may need more than MachinePrecision digits of working precision to meet these tolerances.

During evaluation of In(57):= General::stop: Further output of FindRoot::lstol will be suppressed during this calculation.

During evaluation of In(57):= FindRoot::jsing: Encountered a singular Jacobian at the point {t} = {-6.30218*10^-9}. Try perturbing the initial point(s).

During evaluation of In(57):= FindRoot::jsing: Encountered a singular Jacobian at the point {t} = {-6.30218*10^-9}. Try perturbing the initial point(s).

During evaluation of In(57):= FindRoot::jsing: Encountered a singular Jacobian at the point {t} = {-6.30218*10^-9}. Try perturbing the initial point(s).

During evaluation of In(57):= General::stop: Further output of FindRoot::jsing will be suppressed during this calculation.

During evaluation of In(57):= FindRoot::reged: The point {10000.} is at the edge of the search region {-1000.,10000.} in coordinate 1 and the computed search direction points outside the region.

During evaluation of In(57):= FindRoot::reged: The point {10000.} is at the edge of the search region {-1000.,10000.} in coordinate 1 and the computed search direction points outside the region.

During evaluation of In(57):= FindRoot::reged: The point {10000.} is at the edge of the search region {-1000.,10000.} in coordinate 1 and the computed search direction points outside the region.

During evaluation of In(57):= General::stop: Further output of FindRoot::reged will be suppressed during this calculation.

Out(57)= 0.00650273

In(55):= intSLL(0.5)

Out(55)= 0.00353467

In(56):= intSLL(0.6)

During evaluation of In(56):= FindRoot::lstol: The line search decreased the step size to within tolerance specified by AccuracyGoal and PrecisionGoal but was unable to find a sufficient decrease in the merit function. You may need more than MachinePrecision digits of working precision to meet these tolerances.

During evaluation of In(56):= FindRoot::lstol: The line search decreased the step size to within tolerance specified by AccuracyGoal and PrecisionGoal but was unable to find a sufficient decrease in the merit function. You may need more than MachinePrecision digits of working precision to meet these tolerances.

During evaluation of In(56):= FindRoot::lstol: The line search decreased the step size to within tolerance specified by AccuracyGoal and PrecisionGoal but was unable to find a sufficient decrease in the merit function. You may need more than MachinePrecision digits of working precision to meet these tolerances.

During evaluation of In(56):= General::stop: Further output of FindRoot::lstol will be suppressed during this calculation.

During evaluation of In(56):= NIntegrate::ncvb: NIntegrate failed to converge to prescribed accuracy after 9 recursive bisections in y near {y} = {0.984824086012257}. NIntegrate obtained 0.0293841 -0.119444 I and 0.0017267736029825806` for the integral and error estimates.

During evaluation of In(56):= NIntegrate::ncvb: NIntegrate failed to converge to prescribed accuracy after 9 recursive bisections in y near {y} = {0.984824086012257}. NIntegrate obtained 0.0293841 -0.119444 I and 0.0017267736029825806` for the integral and error estimates.

During evaluation of In(56):= NIntegrate::ncvb: NIntegrate failed to converge to prescribed accuracy after 9 recursive bisections in y near {y} = {0.984824086012257}. NIntegrate obtained 0.0293841 -0.119444 I and 0.001726773577114529` for the integral and error estimates.

During evaluation of In(56):= General::stop: Further output of NIntegrate::ncvb will be suppressed during this calculation.

During evaluation of In(56):= FindRoot::reged: The point {1.} is at the edge of the search region {-1000.,10000.} in coordinate 1 and the computed search direction points outside the region.

During evaluation of In(56):= FindRoot::reged: The point {1.} is at the edge of the search region {-1000.,10000.} in coordinate 1 and the computed search direction points outside the region.

During evaluation of In(56):= FindRoot::reged: The point {1.} is at the edge of the search region {-1000.,10000.} in coordinate 1 and the computed search direction points outside the region.

During evaluation of In(56):= General::stop: Further output of FindRoot::reged will be suppressed during this calculation.

During evaluation of In(56):= NIntegrate::slwcon: Numerical integration converging too slowly; suspect one of the following: singularity, value of the integration is 0, highly oscillatory integrand, or WorkingPrecision too small.

During evaluation of In(56):= NIntegrate::slwcon: Numerical integration converging too slowly; suspect one of the following: singularity, value of the integration is 0, highly oscillatory integrand, or WorkingPrecision too small.

During evaluation of In(56):= NIntegrate::slwcon: Numerical integration converging too slowly; suspect one of the following: singularity, value of the integration is 0, highly oscillatory integrand, or WorkingPrecision too small.

During evaluation of In(56):= General::stop: Further output of NIntegrate::slwcon will be suppressed during this calculation.

Out(56)= 0.00225041 + 8.62966*10^-11 I

In(59):= intSLL(0.7)

During evaluation of In(59):= NIntegrate::slwcon: Numerical integration converging too slowly; suspect one of the following: singularity, value of the integration is 0, highly oscillatory integrand, or WorkingPrecision too small.

During evaluation of In(59):= NIntegrate::ncvb: NIntegrate failed to converge to prescribed accuracy after 9 recursive bisections in y near {y} = {0.99762205831973036103399454788132061366923153400421142578125000000}. NIntegrate obtained 0.00330503 -0.0437457 I and 0.0008224862881109875` for the integral and error estimates.

During evaluation of In(59):= NIntegrate::slwcon: Numerical integration converging too slowly; suspect one of the following: singularity, value of the integration is 0, highly oscillatory integrand, or WorkingPrecision too small.

During evaluation of In(59):= NIntegrate::ncvb: NIntegrate failed to converge to prescribed accuracy after 9 recursive bisections in y near {y} = {0.99762205831973036103399454788132061366923153400421142578125000000}. NIntegrate obtained 0.00330503 -0.0437457 I and 0.0008224862881109875` for the integral and error estimates.

During evaluation of In(59):= NIntegrate::slwcon: Numerical integration converging too slowly; suspect one of the following: singularity, value of the integration is 0, highly oscillatory integrand, or WorkingPrecision too small.

During evaluation of In(59):= General::stop: Further output of NIntegrate::slwcon will be suppressed during this calculation.

During evaluation of In(59):= NIntegrate::ncvb: NIntegrate failed to converge to prescribed accuracy after 9 recursive bisections in y near {y} = {0.99762205831973036103399454788132061366923153400421142578125000000}. NIntegrate obtained 0.00330503 -0.0437457 I and 0.0008224862758539473` for the integral and error estimates.

During evaluation of In(59):= General::stop: Further output of NIntegrate::ncvb will be suppressed during this calculation.

During evaluation of In(59):= FindRoot::reged: The point {1.} is at the edge of the search region {-1000.,10000.} in coordinate 1 and the computed search direction points outside the region.

During evaluation of In(59):= FindRoot::reged: The point {1.} is at the edge of the search region {-1000.,10000.} in coordinate 1 and the computed search direction points outside the region.

During evaluation of In(59):= FindRoot::reged: The point {1.} is at the edge of the search region {-1000.,10000.} in coordinate 1 and the computed search direction points outside the region.

During evaluation of In(59):= General::stop: Further output of FindRoot::reged will be suppressed during this calculation.

Out(59)= 0.0016139 + 2.5821*10^-6 I

To summarize the sample result, intSLL(zl) produces the values for the corresponding zl

0.0149288                         zl=0.3   (with error)
0.00650273                        zl=0.4   (with error)
0.00353467                        zl=0.5
0.00225041 + 8.62966*10^-11 I     zl=0.6   (with error)
0.0016139 + 2.5821*10^-6 I        zl=0.7   (with error)

You can see the trend of the values of the real part.

java – Event Sourcing – More complex example

Usually when I read Event Sourcing examples – they are pretty simple. When trying to implement something even more complex – it seems to get pretty ugly pretty quickly.

Let me explain this on one simple example:

I have a Car and car have Door (2 doors only). Now, the single use-case I have here is startCar – which will open the Door and start the car after the door is open. More complex behavior here is that Door is an observer and it listens to the changes of other door and sync it’s state here – so If one Door is open, other one will open also.

I start with two Adapters (Ports & Adapters architecture) (one for HTTP – RestController and other for AMQP – AMQPListener) which in the end just map it’s input data to common mapped command object (StartCarCommand) inside CarApplicationService which is basically ApplicationService that is responsible for handling use-cases. This first part of the code is not important for the question – just given for the completeness.

class StartCarCommandMapper{
    StartCarCommand map(StartCarRequest request){
        return new StartCarCommand(request.carId, request.doorNumber);
    }
    StartCarCommand map(StartCarMessage message){
        return new StartCarCommand(message.vehicleIdentifier, message.whichDoorToOpen);
    }
}

class RestController{
    //DTO is specified by the sender
    @AllArgsConstructor
    class StartCarRequest{
        int carId;
        int doorNumber;
    }
    private CarApplicationService service;
    private StartCarCommandMapper mapper;
    void startCarRestEndpoint(StartCarRequest request){
        service.startCar(mapper.map(request));
    }
}

class AMQPListener{
    //DTO is specified by the sender
    @AllArgsConstructor
    class StartCarMessage{
        int vehicleIdentifier;
        int whichDoorToOpen;
    }
    private CarApplicationService service;
    private StartCarCommandMapper mapper;
    void onMessage(StartCarMessage message){
        service.startCar(mapper.map(message));
    }
}

class CarRepository{
    CarAggregate getCarById(CarId carId){
        //this would load all events from stream and apply 1 by 1
        return new CarAggregate(carId, Set.of(
                new Door(DoorId.of(1), false),
                new Door(DoorId.of(2), false)
        ));
    }

    public void saveEventStream(CarId carId, List<Object> allEvents) {
        //here we save all events for this aggregate Id to database
    }
}

class CarApplicationService{
    @AllArgsConstructor
    public static class StartCarCommand{
        int carId;
        int doorId;
    }

    private CarRepository repository;

    void startCar(StartCarCommand command){
        CarId carId = CarId.of(command.carId);
        CarAggregate aggregate = repository.getCarById(carId);
        List<DoorOpenedEvent> event1 = aggregate.openDoor(DoorId.of(command.doorId));
        CarStartedEvent event2 = aggregate.startCar();

        List<Object> allEvents = new ArrayList<>(event1);
        allEvents.add(event2);
        repository.saveEventStream(carId, allEvents);
    }
}

Now we come to the interesting part of the domain – Aggregate root which is Car and one entity/vo – Door.

@Builder(toBuilder = true)
class CarAggregate{
    private CarId id;
    private Map<DoorId, Door> doors;
    private boolean started;
    private Set<Door> observers;

    public CarAggregate(CarId id, Set<Door> doors){
        this.id = id;
        this.doors.putAll(doors.stream().collect(Collectors.toMap(Door::getDoorId, Function.identity())));
        this.started = false;
        this.observers.addAll(doors);
    }

    public List<DoorOpenedEvent> openDoor(DoorId doorId) {
        if(!doors.containsKey(doorId)){
            throw new DoorsWithThatIdNotPresent();
        }
        List<DoorOpenedEvent> allEvents = new ArrayList<>();
        DoorOpenedEvent event = doors.get(doorId).open();
        allEvents.add(event);

        //This should be done in loop, since one change can lead to other change etc.
        List<DoorOpenedEvent> fromObservables = observers.stream()
                .map(o -> o.notifyObserver(event))
                .flatMap(Optional::stream)
                .collect(Collectors.toList());

        allEvents.addAll(fromObservables);

        fromObservables.forEach(this::applyEvent); //!!!!<<--- ONLY NOW TO APPLY ALL EVENTS?
        return allEvents;
    }

    public CarStartedEvent startCar() {
        if(started){
            throw new CarAlreadyRunning();
        }
        CarStartedEvent event = CarStartedEvent.of();
        applyEvent(event);
        return event;
    }

    void applyEvent(DoorOpenedEvent event){
        doors.get(DoorId.of(event.getDoorId())).applyEvent(event);
    }

    void applyEvent(CarStartedEvent event){
        started = true;
    }

    class DoorsWithThatIdNotPresent extends RuntimeException{}
    class CarAlreadyRunning extends RuntimeException{}
}

@Builder(toBuilder = true)
@Getter
class Door{
    private DoorId doorId;
    private boolean open;

    public DoorOpenedEvent open(){
        if(open){
            throw new DoorAlreadyOpenException();
        }
        DoorOpenedEvent event = DoorOpenedEvent.of(doorId.getValue());
        //applyEvent(event); //SHOULD IT BE HERE, OR TO BUBBLE UP?
        return event;
    }

    Optional<DoorOpenedEvent> notifyObserver(DoorOpenedEvent event){
        return syncWithOtherDoor(event);
    }

    private Optional<DoorOpenedEvent> syncWithOtherDoor(DoorOpenedEvent event){
        if(!this.open) {    //opposite doors are open now, but we are closed, so sync with other door
            return Optional.of(DoorOpenedEvent.of(doorId.getValue()));
        }
        return Optional.empty();
    }

    void applyEvent(DoorOpenedEvent event){
        open = true;
    }

    class DoorAlreadyOpenException extends RuntimeException{}
}

Questions are:

  1. Should I apply DoorOpenedEvent immediatelly inside Door, or should I bubble it up to the Aggregate root (in this case Car) and only then apply it to the all entities in hierarchy below (as I do now with fromObservables.forEach(this::applyEvent);)?
  2. Is the current Observer pattern correct, since I’m passing only generated Domain Events to interested object parties – but those objects now have to guess what changed only based on those events (since real changes will happen only after when I call fromObservables.forEach(this::applyEvent);?

dg.differential geometry – almost complex $mathbb{Z}^{6}$-action

It is convenient to write almost complex structures in terms of a complex linear coframing. (See my book Introduction to Exterior Differential Systems.) Take complex coordinates $z_1,z_2,z_3$ on $mathbb{C}^3$, for the usual complex structure, and then write real and imaginary parts as $x_k+iy_k=z_k$. Define complex valued 1-forms $theta_1=dz_1+sin(x_2)dbar{z}_3,theta_2=dz_2,theta_3=dz_3$. Write out $dtheta_k$ in terms of $theta_k,bartheta_{ell}$, and find that the torsion is not zero just when there is a $(0,2)$ term (as proven in my book), i.e. $bartheta_kwedgebartheta_{ell}$. Since there are such terms, the torsion is not zero, i.e. the unique $J$ for which these are complex linear is not a complex structure. It is invariant under any translation of $z_1,z_3,y_2$ and under any $2pi$ integer multiple translation of $x_2$.

graphics – How to plot a set of complex numbers with given argument and absoulute value bounds

I want to plot the following complex numbers $$z in text{(complex numbers)}:pi/4 < arg (z) leq 5 pi/4, 1 leq |z| < 2 $$

I don’t know how to graph it so that it would look like 2D without any unecessary details. The closest I found how I want it to look is, when I looked at how graphing of parametric function looks. I tried to use contour plot to graph it, but I just can’t seem to do it…

ContourPlot( Im(F(z(x, y))), {3 pi/4 < arg (z) <= 5 pi/4, 1 <= abs (z) < 2}, {x, -.2, .2}, {y, -.2, .2}, PlotRange -> All, Contours -> Range(-5, 5, .5), ContourLabels -> True)

Does anybody know how to graph my set?

complex analysis – Roots of unity – solving $z^n = 1$ and $z^n = -1$

If we are solving $z^n = 1$, the unique solutions are given by $e^{itheta} $ with $theta$ being each of the angles you get when you split up $2pi$ into $n$ angles (sorry for the bad wording – I didn’t know how else to phrase it).

In a solution to a problem, the author solves $z^4 + 1 = 0$, and it is deduced that $z = e^{ipi/4}, e^{3ipi/4}, e^{5ipi/4}, e^{7ipi/4}$.

So is solving $z^n + 1 = 0$ equivalent to solving $z^n = 1$? And if so, why?

plotting – Solve complex equation in mathematica

How can I solve the following equation in Mathematica?

enter image description here

the parameter tao is as follows:

enter image description here

The value of the other parameters are dh/R=90000, ln A=-235.5, beta=0.85 and x=0.6. All parameters are consistent with the units.

Question:

After solving the equation I would like to make the following plot of Tf-Ta vs Log ta (log ta is simply log t and goes from -2 to 6. Ta is simply T and goes from 75 to 107):

enter image description here

Note: For reference, the equation above is called the Tool-Narayanaswamy-Moynihan (TNM) equation