Defining functions with exponentials

1 view (last 30 days)
I defined the function below in Matlab where my parameters are x and constants v, data, t. I tried to test the function but the function generates errors relating to the exponents. Attached is an image of the function. P*m*((1-e^(-(p+(q_m q_0)/(q_(0+) (q_m-q_0)e^(-vw) ))*t)))/(P+ ((q_m q_0)/(q_(0+) (q_m-q_0)e^(-vw) ))*e^(-(P+ ((q_m q_0)/(q_(0+) (q_m-q_0 ) e^(-vw) ))*t) )
function res= Bass(x,v,data ,t)
%objective function
F=[-data + (x(1)*x(2)*((1- exp*(-x(1)-((x(3)*x(4))/(x(4)+(x(3)-x(4))*exp(-x(5)*v))))*t)/...
(x(1) + ((x(3)*x(4)) / (x(4)+((x(3)-x(4))*exp(-x(5)*v)))) * exp(-x(1) - ((x(3)*x(4)) /( x(4)+(x(3)-x(4))*exp(-x(5)*v))))*t)))];
res=sum(F.^2)

Accepted Answer

Florian Floh
Florian Floh on 13 Jul 2018
In the very first line of your code, you misplaced the '*' (you placed it right after the 'exp' expression. I tried the following code by myself and it worked flawlessly. I hope my answer was helpful.
% This one should work:
F=[-data + (x(1)*x(2)*((1- exp((-x(1)-((x(3)*x(4))/(x(4)+(x(3)-x(4))*exp(-x(5)*v))))*t))/... (x(1) + ((x(3)*x(4)) / (x(4)+((x(3)-x(4))*exp((-x(5)*v)))) * exp(-x(1) - ((x(3)*x(4))) /( x(4)+(x(3)-x(4))*exp((-x(5)*v))))*t))))]; res=sum(F.^2)
  1 Comment
Honey Adams
Honey Adams on 13 Jul 2018
you saved my life Florian.:).I went through over ten times.

Sign in to comment.

More Answers (0)

Categories

Find more on Graphics Object Programming in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!