Azzera filtri
Azzera filtri

how to solve exponential equation

3 visualizzazioni (ultimi 30 giorni)
engineer
engineer il 24 Mag 2019
Modificato: dpb il 25 Mag 2019
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!!!

Risposta accettata

dpb
dpb il 25 Mag 2019
Modificato: dpb il 25 Mag 2019
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 Commenti
engineer
engineer il 25 Mag 2019
Modificato: engineer il 25 Mag 2019
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 il 25 Mag 2019
Modificato: dpb il 25 Mag 2019
"... 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???

Accedi per commentare.

Più risposte (1)

dpb
dpb il 24 Mag 2019
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 Commenti
engineer
engineer il 25 Mag 2019
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)
engineer
engineer il 25 Mag 2019
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!!!

Accedi per commentare.

Community Treasure Hunt

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

Start Hunting!

Translated by