matlabodedifferential-equations# How can I get around this error using deval with dde23 in MATLAB?

I am trying to plot a graph between k(t) and k(t-1) of the solution of my delay differential equation. I am pasting the code:

```
% Defining the variables:
X = 0.2;
M_C = 1.523;
a = 15;
sol = dde23(@(k,t,KL) new_func(k,t,KL,X,M_C,a),1,0.5, [1,10] );
t = linspace(1,10);
p_t = deval(sol,t);
p_lagt = deval(sol,t-1);
% Stability boundary for M/C:
M_C_Stab = 1.523;
function dk = new_func(k,t,KL,X,M_C,a)
dk = X*((1-M_C*(1-KL^a))/(M_C*(1-KL^a)))*k;
end
```

This is the error I am getting:

```
>> new_defined_function
Error using deval (line 132)
Attempting to evaluate the solution outside the interval [1.000000e+00, 1.000000e+01] where it is defined.
Error in new_defined_function (line 12)
p_lagt = deval(sol,t-1);
```

Example 2 in this tutorial is what I am referring to but even that code is giving an error. Maybe because its old as ddeval which has been used here has already become deval. I am fairly new to MATLAB and have no idea how to resolve this error. If anyone could help, I'll be more than grateful.

Solution

The error is caused by

```
p_lagt = deval(sol,t-1)
```

`t-1`

is equivalent to `linspace(0,9)`

, and so trying to evaluate the solution at time 0 causes an error as the solution was calculated on the time interval [1,10].

You could fix the error by changing the `p_lagt`

so that it is evaluated on an interval contained in [1,10], for example

```
p_lagt = deval(sol,max(t-1,1))
```

Note in the example you linked to, the solution is calculated on the time interval [0,100], while `t = linspace(2,100)`

. To mirror this in your code try

```
sol = dde23(@(k,t,KL) new_func(k,t,KL,X,M_C,a),1,0.5, [0,10] ); % note change in time interval
t = linspace(1,10);
p_t = deval(sol,t);
p_lagt = deval(sol,t-1);
```

- how to reshape a cell array to matrix in desired size
- Using Mat_CreateVer for MATLAB versions higher than 7.3
- Making a numpy ndarray matrix symmetric
- Matlab 2021 and2023 cross compatability
- How to plot figures at the end of the for loop MATLAB?
- Variable transfer from App Designer to general .m script file
- Anomalous behavior of the Simulink signal - Simscape
- What is the fastest method to searsch for a part of a matrix inside of a large matrix?
- Can I Prevent Git from Using XTerm Escape Sequences?
- Use VPA to evaluate tiny probabilities
- Generate Array of Random Numbers with Specified Standard Deviation and Mean
- Matlab update plot with multiple data lines/curves
- Matlab vectorize for loop (grid depends on loop index)
- How to use a flag variable to break all the for-loops in spmd statement?
- How to produce the indexes from pdist2 function in Octave?
- Calculation of sensitivity and specificity from confusion matrix
- How do I read comma separated values from a .txt file in MATLAB using textscan()?
- How do you code Garson's algorithm in matlab to find the relative importance of parameters when training a neural network model?
- add data label to a grouped bar chart in matlab
- Using 1D convolutional with same shape so it will work with FFT?
- super fast median of matrix in OpenCV (as fast as MATLAB)
- How to create a struct or type from a dictionary in Julia?
- MATLAB Delay an Input Signal
- Is there an Octave equivalent of Matlab's `contains` function?
- Matlab define callback function for mouse click on a biograph
- getting a return value from a function in MATLAB
- How to convert nifti file to AFNI file?
- load .mat file, but not on the workspace
- Fast plane fitting to many points
- Cubic spline interpolation vs polynomial interpolation