Unforeseen error in running script: 'fmincon' and function evaluation. What could be wrong?

Dear readers,
I am trying to evaluate a likelihood function, but I get this unforeseen error (attachment). I still get output, but it is unclear to me what the error means and how I can resolve it.
Thank you for your time and effort.
All the best,

5 件のコメント

Rik
Rik 2018 年 2 月 24 日
Please show your code, so we can try to reproduce it.
Sean
Sean 2018 年 2 月 24 日
Hi Rik,
It is a rather long code. We have been programming the stochastic volatility model, and need to evaluate the likelihood for parameter estimation. If it is possible, I can add the codes here?
Rik
Rik 2018 年 2 月 24 日
Preferably, you would reduce your code to a MWE. This can often help in find the bug yourself, but failing that, it will make it easier for others to debug. Just make sure we have all relevant file. You can attach Matlab files the same way you attached the image of the error, and if you need other files, you can upload a zip file. If it is short enough, you can add the code in a post. Just make sure to use correct formatting.
Sean
Sean 2018 年 2 月 24 日
I have added both .m files.
Rik
Rik 2018 年 2 月 24 日
You forgot to attach the excel file. I replaced it with a 100x1 random vector, just to check the rest of the code, and for me it runs without errors.
Two other remarks: clc,clear all,close all is cargo cult programming. At the very least you should replace clear all with clear variables. It is better to separate workspaces by using functions. clear all also removes breakpoints, which are an invaluable tool of debugging.
The second remark is that Matlab has a function for infinity: inf. This didn't introduce errors for me, so if there isn't a technical reason because of your project, you shouldn't need to encode another value for infinity.

回答 (1 件)

Sean
Sean 2018 年 2 月 24 日

0 投票

Thank you for the tips! Still a lot to learn. I will be home again in a few hours and try to incorporate your suggestions.

この質問は閉じられています。

質問済み:

2018 年 2 月 24 日

閉鎖済み:

2021 年 8 月 20 日

Community Treasure Hunt

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

Start Hunting!

Translated by