Writing a function in MATLAB
显示 更早的评论
I want to simply write this mathemtical equation in MATLAB, but I am getting some error. Please help.
13 个评论
Sam Chak
2023-10-1
Would it be possible for you to furnish us with the MATLAB code in question and highlight the specific error that you are encountering? Such information would greatly facilitate our ability to assist you in rectifying the issue at hand.
Click this icon
to insert the MATLAB code.
Kashif Naukhez
2023-10-1
Dyuman Joshi
2023-10-1
编辑:Dyuman Joshi
2023-10-1
Please attach the excel file so that we can run your code and reproduce the error you obtained.
In your above comment, did you copy and pasted the full error message you got i.e. all of the red text? If not, then copy and paste the full error message.
Additionally, it's not clear to me what the objective of the optimization is? Is it to minimize the sum you have defined or maximize it?
Kashif Naukhez
2023-10-1
Kashif Naukhez
2023-10-1
diffun = A*(1-(1-q(1))*beta(1)*x).^(1/1-q(1)) + (1-A)*(1-(lambda/beta(2))+(lambda/beta(1))*exp((q(2)-1)*beta(2)*x)).^(1/1-q(2));
in the term
(1-(1-q(1))*beta(1)*x).^(1/1-q(1))
(1-(1-q(1))*beta(1)*x) --> (1-1+q(1))*beta(1)*x) --> q(1)*beta(1)*x
or is there a typo in the formula as written?
Then the exponent
.^(1/1-q(1)) --> .^(1-q(1))
Was that intended to be
.^(1/(1-q(1)))
instead?
Kashif Naukhez
2023-10-1
Dyuman Joshi
2023-10-1
Yes, it was intended as the last line of code you wrote @dpb, as can be seen in the pdf shared by OP.
However the error still persists after making the correction.
I suspect (probably) because optimization is not the way to go here.
Kashif Naukhez
2023-10-1
Sam Chak
2023-10-1
The x-data in the 'Double_q.xlsx' spreadsheet is not sorted in ascending order; it appears to resemble an exponential decay when sorted in Excel.

采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Language Support 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!