Writing a function in MATLAB
Afficher commentaires plus anciens
I want to simply write this mathemtical equation in MATLAB, but I am getting some error. Please help.
13 commentaires
Sam Chak
le 1 Oct 2023
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
le 1 Oct 2023
Modifié(e) : Dyuman Joshi
le 1 Oct 2023
Kashif Naukhez
le 1 Oct 2023
Dyuman Joshi
le 1 Oct 2023
Modifié(e) : Dyuman Joshi
le 1 Oct 2023
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
le 1 Oct 2023
Kashif Naukhez
le 1 Oct 2023
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
le 1 Oct 2023
Dyuman Joshi
le 1 Oct 2023
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
le 1 Oct 2023
Sam Chak
le 1 Oct 2023
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.

Réponse acceptée
Plus de réponses (0)
Catégories
En savoir plus sur Language Support dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!