Calculation using Integrate & Plot take too long time & some error

I want to plot this equation.

enter image description here

mu, Eb, gamma, Eg are constant parameters and x is independent parameter.

\[Mu] := 1; Eb := 0.040; \[CapitalGamma] := 1;(*Fitting parameter*) Eg := 2.354 Ebj := Eg - Eb/j^2 c := 1.4 (*fitting parameter*) A[x_?NumericQ] := \[Mu]^2/x (Sum[(2 Eb /j^3 Sech[(x - Ebj)/\[CapitalGamma]]), {j, 1, 10}] +  Integrate[Sech[(x - e)/\[CapitalGamma]] 1/(1 - c (e - Eg))(*1/(1-  E[-2 Pi Sqrt[Eb/(e-Eg)]])*) , {e, Eg, 2.355}])  Plot[A[x], {x, 2.0, 3.5}] 

There are two problem.

  1. Above the equation, I omit (1/(1-E[-2 Pi Sqrt[Eb/(e-Eg)]])) part because of NIntegrate : non-numerical values error. (maybe divergence issue)
  2. Although I omit some part, It takes too long time to Plot.

How remove that error and save calculation time?

Thank you

Cache mapping calculation

A cache has following specifications:
Block size = 16 Bytes
Set size = 2 way set associative
Number of sets = 128
Physical address = 23 bits, byte addressable

My Questions are:
1) How many blocks main memory contains?
2) What is the extra memory required for cache?

Please help. Thanks in advance.

Calculation in Calculated Column varying based on null values?

Here’s one I’ve never dealt with before: I have calculated columns (in a SharePoint 2013 survey) that calculate values based on particular survey questions. One of those values, however, is an “N/A” value (currently set to the number zero). What I’m trying to do is this – I need to create an average of the NON-N/A answers. For example – I have 4 survey questions from which I extrapolate an average. If one of the of the answers is N/A, I need to get the average of the other three only. What should my calculated column formula be? I’ve never fathomed this one before.

How to reduce the time of calculation using ParalleDo instead of Do Loop?

I am trying to use ParalleDo function through ParametricNDSolveValue and NIntegrate.

The question is pretty similar how to apply paralleDo to my code

First I intend to use Do loop and its works fine but It cost a longer time, so to reduce the computational time I want to use ParalleDo, but I get an error message and I don’t understand where it comes from.

Moreover, I intend to write the output data in data file formate by using

  file = OpenWrite[        "file1.dat",         FormatType -> TableForm]; 

But I got the following error OutputStream[file1.dat ,3] is not open.

Below is my minimal working code and some comments:

 l1 = 0.81;         Z = 1500;         x0 = 10;         v0 = 0.02;         \[Epsilon] = $  MachineEpsilon;          l0 = 0.0714`20.;          ps = ParametricNDSolveValue[{y''[r] +                2 y'[r]/r == -4 \[Pi] l k Exp[-y[r]], y[\[Epsilon]] == y0,              y'[\[Epsilon]] == 0, WhenEvent[r == 1, y'[r] -> y'[r] + Z l]}, {y,              y'}, {r, \[Epsilon], R}, {k, l},             Method -> {"StiffnessSwitching"}, AccuracyGoal -> 5,             PrecisionGoal -> 4, WorkingPrecision -> 15];        file = OpenWrite[            "file1.dat",             FormatType -> TableForm];         ParallelDo[x = i x0;           v = i^3 v0;           R = Rationalize[v^(-1/3), 0];           l = Rationalize[l1/(i x0), 0];           nn = FindRoot[Last[ps[y0, l]][R], {y0, -1}, Evaluated -> False][[1,              2]];           Tot = 4 \[Pi] nn NIntegrate[              r^2 Exp[-First[ps[nn, l]][r]], {r, \[Epsilon], R},               PrecisionGoal -> 4];           Print[NumberForm[i*1., 5], "  ", NumberForm[Tot, 5]];, {i, 292/100,             31/10, 1/100}] // Quiet // AbsoluteTiming Close[file]; 

Implementing a better algorithm for calculation of bacterial growth

I am working on a mathematical model that describes the growth of 4 different bacterial populations and immune system cells under certain conditions. The model is governed by the equations below.

POPULATION 1:

$ {\underbrace{\frac{dN_{PS}}{dt}}_{\text{ Population change rate }}=\underbrace{r N_{PS}}_{\text{ Exponential growth }}\cdot\underbrace{\left(1-\frac{N_{PS}+N_{PR}}{K}\right)}_{\text{ Growth limitation }}-\underbrace{\theta_{PS}N_{PS}}_{\text{ Natural death }}-\underbrace{A_{PS}N_{PS}}_{\text{Biofilm formation}}+\underbrace{D_{BS}N_{BS}}_{\text{Biofilm dispersion}}-\underbrace{\phi_{PS}N_{PS}}_{\text{Mutation rate}}-\underbrace{\eta\delta_{PS}A_{m}N_{PS}}_{\text{Antibiotic inhibition}}-\left\{ \underbrace{\Gamma N_{PS}I}_{\text{Immune system}}\right\} }$

POPULATION 2:

$ {\frac{dN_{BS}}{dt}=(r-c_{b})N_{BS}\cdot\left(1-\frac{N_{BS}+N_{BR}}{K}\right)-\theta_{BS}N_{BS}+A_{PS}N_{PS}-D_{BS}N_{BS}-\phi_{BS}N_{BS}-\eta\delta_{BS}A_{m}N_{BS}-\left\{ \Gamma N_{BS}I\right\} }$

POPULATION 3:

$ {\frac{dN_{PR}}{dt}=(r-c_{r})N_{PR}\cdot\left(1-\frac{N_{PS}+N_{PR}}{K}\right)-\theta_{PR}N_{PR}-A_{PR}N_{PR}+D_{BR}N_{BR}+\phi_{PS}N_{PS}-\eta\delta_{PR}A_{m}N_{PR}-\left\{ \Gamma N_{PR}I\right\} }$

POPULATION 4:

$ {\frac{dN_{BR}}{dt}=(r-(c_{b}+c_{r}))N_{BR}\cdot\left(1-\frac{N_{BS}+N_{BR}}{K}\right)-\theta_{BR}N_{BR}+A_{PR}N_{PR}-D_{BR}N_{BR}+\phi_{BS}N_{BS}-\eta\delta_{BR}A_{m}N_{BR}-\left\{ \Gamma N_{BR}I\right\} }$

NAIVE CELLS (IMMUNE SYSTEM):

$ {\frac{dV}{dt}=\frac{-\sigma VB}{\pi+B}}$

EFFECTOR CELLS (IMMUNE SYSTEM):

$ {{\frac{dE}{dt}=(2\sigma V+\sigma E)\cdot\frac{B}{\pi+B}-hE\left(1-\frac{B}{\pi+B}\right)}}$

MEMORY CELLS (IMMUNE SYSTEM):

$ {{\frac{dM}{dt}=fEh\left(1-\frac{B}{\pi+B}\right)}}$

TOTAL BACTERIAL DENSITY:

$ {\frac{dB}{dt}=N_{PS}+N_{PR}+N_{BS}+N_{BR}}$

IMMUNE SYSTEM DENSITY:

$ {\frac{dI}{dt}=V+E+M}$

ANTIBIOTIC UPTAKE 1:

$ {{\eta}=\begin{cases} 1 & t_{1}\leq t\leq t_{1}+t_{2}\ 0 & t_{1}>t\:or\:t>t_{1}+t_{2} \end{cases}}$

ANTIBIOTIC UPTAKE 2:

$ {{\eta}=\begin{cases} 1 & B\geq\varOmega\ 0 & B<\varOmega \end{cases}}$

I am interested in how $ N_{PS}, N_{PR}, N_{BS}, N_{BR}, V, E, M $ change over time for which I implemented an algorithm in Python to solve the equations. Greek letters and other undescribed parameters (e.g. r, K, etc.) are mainly constants that are set at the beginning of the execution of the program.

One example of the functions used is shown below. Currently as you can also see from the code I’m using an Euler method to solve the equations, however I’d like to implement at least Heun’s method or even some higher order Runge-Kutta method to solve them.

I’m stuck already with Heun’s method and don’t know how to implement it. I ask for help with how to modify the following code and change it to for example Heun’s if that’s even possible with those equations.

def sensitive_bacteria_PS(previous_density, growth_rate, density_PR, maximum_density_P, death_rate_PS, attachment_rate_PS, mutation_rate_PS, antibiotic_uptake, antibiotic_inhibition_PS, antibiotic_concentration, lymphocyte_inhibition, total_immune_cells, detachment_rate_BS, density_BS, time_step):      return previous_density + ((previous_density * (growth_rate * (1 - (previous_density + density_PR) / maximum_density_P) - death_rate_PS - attachment_rate_PS - mutation_rate_PS - antibiotic_uptake * antibiotic_inhibition_PS * antibiotic_concentration - lymphocyte_inhibition * total_immune_cells) + detachment_rate_BS * density_BS) * time_step) 

Cause of disparity between methods of calculation of specific angular momentum?

I’m trying to numerically solve for the delta-V cost of a transfer between two close elliptic orbits which are inclined relative to each other. The method I’m using essentially calculates the velocity vectors of the initial orbit at one node, the final orbit at the opposing node, and then calculates the transfer orbit from initial flight path angle, initial radius, and final radius.

One key step is to calculate the specific angular momentum vector and eccentricity vector of the transfer orbit, in order to calculate the perifocal-to-inertial direction cosine matrix for the transfer orbit. However, when I calculate the angular momentum vector h of the transfer orbit in the inertial frame from the cross product of the position and velocity vectors in the inertial frame, I find significant error (relative error is -3.9521e-8) between the magnitude of this vector and the scalar specific angular momentum calculated earlier in the code.

This is strange to me because that scalar angular momentum is used to calculate the velocity vector. I’m confused as to where the loss of precision is occurring.

I’ve tried providing inputs with greater precision, specifically the mu value I have been using, but this did not shift the relative error at all. When I use the same cross product method to calculate specific angular momentum of orbits 1 and 2, the error is on the order of machine precision.

”’MATLAB

    mu = 3.98600437823e+14;      thetaNT = -55.1582940061466; % deg     eT = 0.022905923178296;     aT = 7.243582592195826e+06; % m      r1A = 7.146263097977215e+06; % m     v1RA = -1.390985544431790e+02; % m/s     v1ThetaA = 7.494958913236144e+03; % m/s      eR1 = [0.355828643065080;-0.934551216774375;0];     eTheta1 = [0.934551216774375;0.355828643065080;0];      nCpf1 = [0.263190394679355,-0.840751409136755,0.473146789255815;         0.880932410956014,0.00949753358184791,-0.473146789255815;         0.393305102275257,0.541338032000730,0.743144825477394];     nCpf2 = [0.107314578042381,-0.875080710676727,0.471929370924401;         0.879361618777851,-0.137938482815824,-0.455736896003458;         0.463903788257849,0.463903788257849,0.754709580222772];       v1A = sqrt(v1RA^2 + v1ThetaA^2); % Total speed of orbit 1 at A     r1A = K1;      hT = sqrt(aT*mu*(1-eT^2)); % Specific angular momentum of transfer orbit      eRTB = [-cosd(thetaNT);sind(thetaNT+180);0];     eThetaTB = [-sind(thetaNT+180);-cosd(thetaNT);0];      % Calculation of radial speed and tangential speed     vTRA = mu/hT*eT*sind(thetaNT);     vTThetaA = mu/hT*(1+eT*cosd(thetaNT));      vTA = sqrt(vTRA^2+vTThetaA^2);      vTRB = mu/hT*eT*sind(thetaNT+180);     vTThetaB = mu/hT*(1-eT*cosd(thetaNT));      % Conversion of radius and speeds into radius and velocity vectors     % in perifocal frames     r1APF1 = r1A.*eR1;     v1APF1 = v1RA.*eR1 + v1ThetaA.*eTheta1;      vTBPFT = vTRB.*eRTB + vTThetaB.*eThetaTB;      v2BPF2 = v2RB.*eR2 + v2ThetaB.*eTheta2;      % Conversion to inertial reference frame     r1AN = nCpf1*r1APF1;     v1AN = nCpf1*v1APF1;      v2BN = nCpf2*v2BPF2;      rTAN = r1AN;     vTAN = v1AN.*(vTA/v1A);      % Calculation of angular momentum and eccentricity vectors in     % inertial frame     hTN = cross(rTAN, vTAN);     diff = (norm(hTN)-hT)/hT 

”’

I would expect diff to be on the order of machine precision, roughly 2.2e-16, but it is instead on the order of 1e-8, 8 orders of magnitude larger than it should be.

Factorial calculation UI freezes on loading many items in ListBox

I’ve been experiencing this performance issue for about 3 days and really need your help. I’m a novice at c# and cannot understand what I can do to optimize my application.

The problem is that the UI is not as responsive as it must be while many items are loading.

I decided to write an application on learning purpose where we can calculate factorial of the input big number. It’s also important to make calculations concurrently in several threads.

I also want to bind a progress bar to the progress of calculations and show interim calculations.

For example: Input number: 5

Interim calculations:

0!=1 1!=1 2!=2 3!=6 4!=24 5!=120 

Result: 5!=120

Everything is fine when the input number is less then 1000. If it’s more then freezes are coming.

What I’ve tried:

  1. At first I’ve tried to write my own observable concurrent collection where I add my items from other threads.
  2. Then I’ve tried to push interim results, which are calculated by other threads, into ConcurrentQueue from which I will dequeue them into my observable collection.
  3. I’ve tried to turn on virtualization but it also didn’t help. Actually, I’m pretty sure that the problem is in my collection that ItemSource is binded to is growing and when I add more elements to this collection then it starts redrawing completly.

CalculationProcessView:

<UserControl x:Class="FactorialCalculator.WPF.Views.CalculationProcessView"          xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"          xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"          xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"           xmlns:d="http://schemas.microsoft.com/expression/blend/2008"           xmlns:local="clr-namespace:FactorialCalculator.WPF.Views"          mc:Ignorable="d"           d:DesignHeight="450" d:DesignWidth="800">  <StackPanel>     <Label Content="Calculation:"/>      <Border BorderBrush="Gainsboro" BorderThickness="0,2">         <ListBox              x:Name="CalculationProcessListBox"             Height="100"             ItemsSource="{Binding Path=Calculations, Mode=OneWay, IsAsync=True}"             VirtualizingPanel.IsContainerVirtualizable="True"             VirtualizingPanel.IsVirtualizing="True"             VirtualizingPanel.VirtualizationMode="Recycling"             VirtualizingPanel.CacheLengthUnit="Page"             VirtualizingPanel.CacheLength="2,2">              <ListBox.Template>                 <ControlTemplate>                     <ScrollViewer>                         <ItemsPresenter />                     </ScrollViewer>                 </ControlTemplate>             </ListBox.Template>              <ListBox.ItemsPanel>                 <ItemsPanelTemplate>                     <VirtualizingStackPanel />                 </ItemsPanelTemplate>             </ListBox.ItemsPanel>          </ListBox>     </Border>      <ProgressBar Minimum="0"                  Maximum="{Binding ProgressBarMaxValue}"                  Value="{Binding Calculations.Count, Mode=OneWay}"                  Height="28" /> </StackPanel> 

CalculatorFormViewModel:

namespace FactorialCalculator.WPF.ViewModels {     public class CalculatorFormViewModel : BaseViewModel, ICalculatorFormViewModel     {         private string _progressBarMaxValue;         private ICommand _calculateCommand;         private IModelFactory _modelFactory;         private SystemTimer _dispatcherTimer;         private ICalculationModel _calculation;         private ICommandFactory<RelayCommand> _commandFactory;         private IFactorialCalculationService _factorialCalculationService;         private static object _syncLock = new object();          public CalculatorFormViewModel(Dispatcher uiDispatcher,                                        IModelFactory modelFactory,                                        ICommandFactory<RelayCommand> commandFactory,                                        IFactorialCalculationService factorialCalculationService) : base(uiDispatcher)         {             _modelFactory = modelFactory;             _commandFactory = commandFactory;             _factorialCalculationService = factorialCalculationService;             _calculation = _modelFactory.CreateCalculationModel();             Calculations = new ConcurrentSortedList<ICalculationModel>();             BindingOperations.EnableCollectionSynchronization(Calculations, _syncLock);         }          public ConcurrentSortedList<ICalculationModel> Calculations { get; set; }          public string ProgressBarMaxValue         {             get { return _progressBarMaxValue; }             set             {                 _progressBarMaxValue = value;                 NotifyPropertyChanged("ProgressBarMaxValue");             }         }          public ICalculationModel Calculation         {             get             {                 return _calculation;             }             set             {                 _calculation = value;                 NotifyPropertyChanged("Calculation");             }         }          #region ICalculatorFormViewModel implementation          public ICommand CalculateCommand         {             get             {                 return _calculateCommand ??                   (                       _calculateCommand                             = _commandFactory.CreateCommand(                                  _ => this.Calculate().FireAndForgetSafeAsync(null))                   );             }         }          public async Task Calculate()         {             if (_factorialCalculationService.IsInPorcess)             {                 _factorialCalculationService.StopCalculation();             }              if (BigInteger.TryParse(Calculation.InputNumber, out BigInteger number))             {                 try                 {                     Calculations.Clear();                      ProgressBarMaxValue = Calculation.InputNumber;                     StartMonitoringCalculationProgress();                      await _factorialCalculationService.StartCalculation(number);                 }                 finally                 {                     StopMonitoringCalculationProgress();                 }             }             else             {                 throw new ArgumentException("Incorrect input value!");             }         }          #endregion          protected void StartMonitoringCalculationProgress()         {             _dispatcherTimer = new SystemTimer() { Interval = 500 };              _dispatcherTimer.Elapsed += (o, args) =>             {                  if (_factorialCalculationService                             .TryGetInterimResults(out IDictionary<BigInteger, BigInteger> interimResults))                 {                     lock (_syncLock)                     {                         Calculations.AddItems(                             interimResults.Select(                                     (item) =>                                     {                                         var calculationModel = _modelFactory.CreateCalculationModel();                                          calculationModel.InputNumber = item.Key.ToString();                                         calculationModel.Factorial = item.Value.ToString();                                          return calculationModel;                                     }                                 ).ToList()                         );                     }                 }             };              _dispatcherTimer.Start();         }          protected void StopMonitoringCalculationProgress()         {             _dispatcherTimer.Stop();             _dispatcherTimer.Dispose();         }     } } 

FactorialCalculationService:

namespace FactorialCalculator.Application.Services {     public class FactorialCalculationService : IFactorialCalculationService     {         private bool _isCanceled;         private bool _isInPorcess;         private CancellationTokenSource _tokenSourse;         private ConcurrentQueue<IDictionary<BigInteger, BigInteger>> _calculationQueue;         private readonly IFactorialCalculatorService _factorialCalculatorService;          public FactorialCalculationService(IFactorialCalculatorService factorialCalculatorService)         {             _isCanceled = false;             _isInPorcess = false;             _factorialCalculatorService = factorialCalculatorService;             _calculationQueue = new ConcurrentQueue<IDictionary<BigInteger, BigInteger>>();         }          #region IFactorialCalculationService implementation          public bool IsInPorcess => _isInPorcess;          public bool TryGetInterimResults(out IDictionary<BigInteger, BigInteger> interimResults)         {             return _calculationQueue.TryDequeue(out interimResults);         }          public Task StartCalculation(BigInteger number)         {             return                  Task.Run(                     () =>                     {                         try                         {                             _isCanceled = false;                             _isInPorcess = true;                             _tokenSourse = new CancellationTokenSource();                              _factorialCalculatorService.Calculate(                                                              number,                                                              (dictionary) => _calculationQueue.Enqueue(dictionary),                                                              _tokenSourse.Token                                                          );                               //Wait while all the results will be consumed                             while (!_calculationQueue.IsEmpty);                         }                         catch (AggregateException ax)                         {                             ax.Handle(ex => {                                 OperationCanceledException exception = ex as OperationCanceledException;                                  if (exception != null)                                 {                                     _isCanceled = true;                                 }                                  return exception != null;                             });                          }                         finally                         {                             _isInPorcess = false;                         }                     }                 );         }          public void StopCalculation()         {             if (!_isCanceled)             {                 _calculationQueue = new ConcurrentQueue<IDictionary<BigInteger, BigInteger>>();                 _tokenSourse.Cancel();             }         }          #endregion     } } 

FactorialCalculatorService:

namespace FactorialCalculator.Domain.Services {     public class FactorialCalculatorService : IFactorialCalculatorService     {         private int _maxTasks;          #region IFactorialCalculatorService implementation          public BigInteger Calculate(BigInteger number,                                     Action<IDictionary<BigInteger, BigInteger>> callback = null,                                     CancellationToken cancellationToken = default(CancellationToken))         {             if (number < 0)                 throw new ArgumentOutOfRangeException(nameof(number));              BigInteger countOfTasks = number / Environment.ProcessorCount;             countOfTasks = countOfTasks > int.MaxValue ? int.MaxValue : (int)countOfTasks;             _maxTasks = countOfTasks == 0 ? 1 : (int)countOfTasks;              var tasks = ParallelizeCalculation(number, callback, cancellationToken);              Task.WaitAll(tasks);              return GetFinalResult(tasks);         }          #endregion           protected virtual BigInteger CalculateClass(BigInteger upperBound,                                                     BigInteger startFrom,                                                     CancellationToken cancellationToken = default(CancellationToken),                                                     Action<IDictionary<BigInteger, BigInteger>> callback = null)         {             cancellationToken.ThrowIfCancellationRequested();              SortedDictionary<BigInteger, BigInteger> calculationHistory = new SortedDictionary<BigInteger, BigInteger>();              for (var i = startFrom; i <= upperBound; i += _maxTasks)             {                 //Thread.Sleep(50);                 cancellationToken.ThrowIfCancellationRequested();                  var internalResult = Calculate(i);                 calculationHistory.Add(i, internalResult);             }              callback?.Invoke(calculationHistory);              return calculationHistory.Last().Value;         }          protected virtual BigInteger Calculate(BigInteger number)         {             BigInteger result = 1;              for (BigInteger i = result; i <= number; i++)             {                 result *= i;             }              return result;         }          protected virtual Task<BigInteger>[] ParallelizeCalculation(BigInteger number,                                                         Action<IDictionary<BigInteger, BigInteger>> callback = null,                                                         CancellationToken cancellationToken = default(CancellationToken))         {             var tasks = Enumerable.Range(0, _maxTasks)                                   .Select(                                             i => Task.Factory.StartNew(                                                 () => CalculateClass(number, i, cancellationToken, callback),                                                 TaskCreationOptions.AttachedToParent                                             )                                          )                                   .ToArray();               return tasks;         }          private BigInteger GetFinalResult(Task<BigInteger>[] tasks)         {             BigInteger finalResult = 1;              foreach(var task in tasks)             {                 finalResult *= task.Result;             }              return finalResult;         }     } } 

ConcurrentSortedList:

namespace FactorialCalculator.WPF.Infrastructure.Collections {     public class ConcurrentSortedList<T> : ObservableCollection<T>     {         private readonly ReaderWriterLockSlim _lock;         private bool suspendCollectionChangeNotification;          public ConcurrentSortedList()             : base()         {             this.suspendCollectionChangeNotification = false;             _lock = new ReaderWriterLockSlim(LockRecursionPolicy.SupportsRecursion);         }          public override event NotifyCollectionChangedEventHandler CollectionChanged;           public void AddItems(IList<T> items)         {             try             {                 _lock.EnterWriteLock();                  this.SuspendCollectionChangeNotification();                  foreach (var i in items)                 {                     Add(i);                 }             }             finally             {                 _lock.ExitWriteLock();             }              this.NotifyChanges();           }         public new void Add(T item)         {             try             {                 _lock.EnterWriteLock();                  int i = 0;                 while (i < Items.Count && Comparer<T>.Default.Compare(Items[i], item) < 0)                     i++;                  Items.Insert(i, item);             }             finally             {                 _lock.ExitWriteLock();             }              OnPropertyChanged(new System.ComponentModel.PropertyChangedEventArgs("Count"));         }           public void NotifyChanges()         {             this.ResumeCollectionChangeNotification();             var arg = new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset);             this.OnCollectionChanged(arg);         }          public void RemoveItems(IList<T> items)         {             try             {                 _lock.EnterWriteLock();                  this.SuspendCollectionChangeNotification();                  foreach (var i in items)                 {                     Remove(i);                 }             }             finally             {                 _lock.ExitWriteLock();             }              this.NotifyChanges();         }          public void ResumeCollectionChangeNotification()         {             this.suspendCollectionChangeNotification = false;         }          public void SuspendCollectionChangeNotification()         {             this.suspendCollectionChangeNotification = true;         }          protected override void OnCollectionChanged(NotifyCollectionChangedEventArgs e)         {              using (BlockReentrancy())             {                 if (!this.suspendCollectionChangeNotification)                 {                     NotifyCollectionChangedEventHandler eventHandler =                           this.CollectionChanged;                     if (eventHandler == null)                     {                         return;                     }                      Delegate[] delegates = eventHandler.GetInvocationList();                      foreach (NotifyCollectionChangedEventHandler handler in delegates)                     {                         DispatcherObject dispatcherObject                              = handler.Target as DispatcherObject;                          if (dispatcherObject != null                                && !dispatcherObject.CheckAccess())                         {                             dispatcherObject.Dispatcher.BeginInvoke(DispatcherPriority.DataBind, handler, this, e);                         }                         else                         {                             handler(this, e);                         }                     }                 }             }         }       } } 

BaseViewModel

public abstract class BaseViewModel : INotifyPropertyChanged {     protected readonly Dispatcher _uiDispatcher;      protected BaseViewModel(Dispatcher uiDispatcher)     {         _uiDispatcher = uiDispatcher;     }      #region INotifyPropertyChanged implementation      public event PropertyChangedEventHandler PropertyChanged;      protected void NotifyPropertyChanged([CallerMemberName] string propertyName = null)     {         var propertyChanged = PropertyChanged;         if (propertyChanged == null)         {             return;         }          _uiDispatcher.Invoke(() => propertyChanged.Invoke(this, new PropertyChangedEventArgs(propertyName)));     }      #endregion } 

App:

enter image description here

Source code: enter link description here

Confusion in speed up calculation for pipeline architecture

This is an online question I am trying to solve.

You are given a non-pipelined processor design which has a cycle time of 10ns and average CPI of 1.4.If a pipelined processor having 5 stages are 1ns, 1.5ns, 4ns, 3ns, and 0.5ns, what is the best speedup you can get compared to the original processor?

Approach I: In a pipelined architecture, in a steady state, the CPI tends to be 1 provided there is no fixed percent of NOPs. Thus Speed up = CPI_non_pipelined / CPI_pipelined = 1.4 /1 = 1.4

Approach II: For converting the execution into pipelined, we need to reduce the cycle to match up phase duration. Thus pipelined cycle should be max of {phase durations} = max of {1ns, 1.5ns, 4ns, 3ns, and 0.5ns} = 4ns. So speed up = cycle_duration_non_pipelined / cycle_duration_pipelined = 10/4 = 2.5

Wondering why is this difference! Any help will be much appreciated.