Value Function Iteration Interpolation Error: Input Coordinates must be real

5 visualizzazioni (ultimi 30 giorni)
Hello, I've attached the most pertinent aspects of my code. The main issue I am having is lines 70-84 during the process of implementing a value function iteration for a specified objective function. I seem to run into a problem of when I specify my parameter psi=0.357 the interpolation procedure found in valfun_v2.m gives an error that the coordinates must be real. Any suggestions or reasons why would be greatly appreciated.
Thanks.

Risposte (1)

Binaya
Binaya il 22 Set 2023
Hi David,
I understand that the interp2 function is receiving complex arguments during execution. This error can occur when you attempt to find the minimum point of 'valfun_v2' between kmin and kmax. As fminbnd sweeps through the values between kmin and kmax, it generates a complex value of k to test the function value.
According to the documentation of the fminbnd function, the function handle provided as an input argument should accept a real scalar and return a real scalar. However, in your case, the function handle of 'valfun_v2' is returning complex values as output. Since the fminbnd function is not designed to handle complex value arguments, your code encounters errors during execution.
You can resolve this issue by following the below troubleshooting steps:
  • You can modify the valfun_v2 function to return the absolute value of the complex number to convert the complex output to a real value suitable for fminbnd.
  • You create a wrapper function that encapsulates valfun_v2 and converts the complex output to a real value. This way, you can use fminbnd without modifying valfun_v2 itself.
For more information on fminbnd function and its expected input format, please refer to the documentation provided here: Find minimum of single-variable function on fixed interval - MATLAB fminbnd - MathWorks India
I hope this helps.
Regards,
Binaya

Categorie

Scopri di più su MATLAB in Help Center e File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by