how to solve exponential equation
1 次查看(过去 30 天)
显示 更早的评论
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!!!
0 个评论
采纳的回答
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 个评论
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 个)
dpb
2019-5-24
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 个评论
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!