how to solve exponential equation

Hi everybody
I have got a mat file that I need to use output for the function. Each row of the mat file will be implemented to the function ( 100 of them) and then each result will be saved as one matrix. The code I used did not help. Can anyone help me out?
load('example.mat');
X = sym( nan(size(ee)) );
for K = 1 : numel(ee)
solution = vpasolve( 0.4075*exp(-((x(K)-14.87)/11.39).^2) + 0.5621*exp(-((x(K)-18.64)/27.74).^2, x));
if isempty(solution)
fprintf('No solution for a(%d)\n', K);
else
X(K) = solution;
end
end
The variable ee is coming from the mat file that I loaded.
Thanks!!!

 采纳的回答

dpb
dpb 2019-5-25
编辑:dpb 2019-5-25
opt= optimoptions('fsolve','Display','none');
X0=15;
soln=arrayfun(@(e) fsolve(@(x) fnE(x)-e,X0,opt),ee);
NB: There are two possible solutions; which one fsolve finds will depend on whether the initial guess is on the LH or RH side of the maximum; the one above finds the RH set; setting X0=13 (say) returns the other.
You give no information as to which is the desired set or if it matters.

2 个评论

Thank you very much for your help. It is highly appreciated and it worked satisfactorily. I approached from LH. The results are between 13-15. I have one more question. When I plot my function, the max point of the function is roughly (0.99, 15.8). What could be the reason that I am not VERY close to 15.8? When I approach from the RH, then the results go over 17, 18? I am aware that the values for y axis is symetrical and we need to approach from one side.
Thanks alot!!!
dpb
dpb 2019-5-25
编辑:dpb 2019-5-25
"... I am aware that the values for y axis is symetrical...."
The y-values around the peak are NOT symmetrical -- the peak is the summation of two gaussians of differing means and variance so while each independently would be symmetric around its mean, the summation is not...the distribution with the higher mean also has almost 3X the magnitude of std as does the lower mean distribution. Hence it is spread far more and this shows up as a broader RH side as compared to LH if reflect the two halves around the peak location.
For the followup question--
You're solving for the point that the functional equals the value -- that isn't the maximum value of the function, it's the value on one or the other sides of the peak. Why would you expect anything else?
Plot the solution X and associated value on the curve and you'll just put X's or O's or whatever symbol of choice on the curve at the intersection points...
Perhaps this is the correct solution but not to the problem you actually were trying to solve???

请先登录,再进行评论。

更多回答(1 个)

fnE=@(x) 0.4075*exp(-((x-14.87)/11.39).^2) + 0.5621*exp(-((x-18.64)/27.74).^2);
ezplot(fnE,[0 100])
hAx=gca;
hL=hAx.Children;
>> yMx=max(hL.YData)
yMx =
0.9612
>> sum(ee<=yMx)
ans =
0
>> min(ee)
ans =
0.9626
>>
The function maximum is roughly 0.9612; the minimum value in you array is 0.9626; there are no values that will solve the equation given the constants...gets fairly close, but can't quite get there...
>> fminsearch(@(x) -fnE(x),15)
ans =
15.5765
>> fnE(ans)
ans =
0.9612
>>

8 个评论

Thanks for the answer. Is there any way to save each x values ( it is going to be all around 15.75) as a matrix (100*1) ? Besides, if you make the fplot(fnE,[0 36]). This will show how my function looks like in a better way.
dpb
dpb 2019-5-24
编辑:dpb 2019-5-24
What X values? There is no solution for any of the values that you've got in your ee array. The maximum your functional can attain is, as shown, 0.9612; the minimum ee is 0.9626.
I am sligtly confused. Why there is no solution? How possible max is 0.9612 and min is 0.9626? When I check ee values, I see that there is a value which is 0.9811. If you explain me why there is no solution, that would be great.
it should be a corresponding x value for each ee value? Although the results are close to each other.
I dont really understand why do you look at min and max values of the ee matrix? I wanna use each row of ee in the function as an output and find the correspoing x value. Hence, I need to calculate 100 x values which possibly change between 15,75 to 16. For example, the first two equtations to calculate the first and second row of x value will be ;
0.9789 = 0.4075*exp(-((x-14.87)/11.39).^2) + 0.5621*exp(-((x-18.64)/27.74).^2
0.9689 = 0.4075*exp(-((x-14.87)/11.39).^2) + 0.5621*exp(-((x-18.64)/27.74).^2
...........
Because there is no x value that will solve either of those two...the max value your equation can have is 0.9612 at x=15.5765 which is what the fminsearch showed (a maximum is a negative minimum).
And, if that is the largest you can get from the equation, unless an ee value is less than or at least equal to that, then there is no solution.
To visualize, added a scatter plot of the ee values and blew up the y axis from the previous ezplot...untitled.jpg
Note there's white space below the smallest ee and the maximum of the peak of the functional. Hence, there's no intersection of the two and "never the twain shall meet".
Thank you very much. I understood now about what is wrong with my function. Now, I edited my function, and the min value is 0.9528 and max of the function is 0.9951. Can we now find the results for each row of e matrix? it shows that min x is 15.48 in the code, and the max will be almost 16. How about the values between these number? Can we find those number? I attached the edited function and its mat file..
load('example.mat');
fnE=@(x) 0.4666*exp(-((x-14.93)/10.86).^2) + 0.5377*exp(-((x-19.07)/29.33).^2);
fplot(fnE,[0 36])
hAx=gca;
hL=hAx.Children;
yMx = max(hL.YData)
sum(e<=yMx);
min(e)
fminsearch(@(x) -fnE(x),10)
Apart from my previous comment, I have tried the following code:
My cell array supposed to give me the x values, however, all values are zero. Am I on the right track?
load('example.mat');
% Loop method
syms x
for i = 1:numel(e)
sol(i) = 0.4666*exp(-((x-14.93)/10.86).^2) + 0.5377*exp(-((x-19.07)/29.33).^2) == e(i);
C = double(sol);
end
Thanks!!!

请先登录,再进行评论。

Community Treasure Hunt

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

Start Hunting!

Translated by