Solve non-linear equation with varying value

I have a equation to solve
exp(-10*z)-9*exp(-2*z)+(8-4*x)=0
here
x=linspace(0,1,101)
Since the equation itself would change to a new equation for each x, i am unable to figure out how to solve it. I need to solve for z. Can somebody suggest an approach to this.

 Réponse acceptée

madhan ravi
madhan ravi le 3 Jan 2019
Modifié(e) : madhan ravi le 3 Jan 2019
x=linspace(0,1,101);
Result=cell(1,numel(x)); % preallocate
for i = 1:numel(x)
Result{i}=fzero(@(z) exp(-10*z)-9*exp(-2*z)+(8-4*x(i)),[0 5]);
% ^^^--initial guess interval
end
celldisp(Result)
[Result{:}] % double array
Gives:
>> [Result{:}]
ans =
Columns 1 through 7
0 0.0049 0.0096 0.0142 0.0187 0.0231 0.0274
Columns 8 through 14
0.0316 0.0357 0.0398 0.0438 0.0477 0.0517 0.0555
Columns 15 through 21
0.0594 0.0632 0.0670 0.0707 0.0744 0.0782 0.0818
Columns 22 through 28
0.0855 0.0892 0.0928 0.0964 0.1001 0.1037 0.1073
Columns 29 through 35
0.1109 0.1145 0.1181 0.1217 0.1252 0.1288 0.1324
Columns 36 through 42
0.1360 0.1396 0.1432 0.1468 0.1504 0.1540 0.1576
Columns 43 through 49
0.1612 0.1648 0.1685 0.1721 0.1758 0.1794 0.1831
Columns 50 through 56
0.1868 0.1905 0.1942 0.1979 0.2016 0.2054 0.2091
Columns 57 through 63
0.2129 0.2167 0.2205 0.2244 0.2282 0.2321 0.2359
Columns 64 through 70
0.2398 0.2438 0.2477 0.2517 0.2556 0.2596 0.2637
Columns 71 through 77
0.2677 0.2718 0.2759 0.2800 0.2842 0.2883 0.2925
Columns 78 through 84
0.2968 0.3010 0.3053 0.3096 0.3140 0.3183 0.3227
Columns 85 through 91
0.3272 0.3317 0.3362 0.3407 0.3453 0.3499 0.3545
Columns 92 through 98
0.3592 0.3640 0.3687 0.3735 0.3784 0.3833 0.3882
Columns 99 through 101
0.3932 0.3982 0.4033
>>

6 commentaires

P K
P K le 3 Jan 2019
Hello Madan,Thanks for your response. But the z value should not be negative.
How you have decided that x0 =0 ? If i change x0, my answers would change. Can you explain a bit .
madhan ravi
madhan ravi le 3 Jan 2019
Modifié(e) : madhan ravi le 3 Jan 2019
Ravi Singh, x0 is the initial guess , why z shouldn't be negative ? , plot the graph to verify?
P K
P K le 3 Jan 2019
Because I have a plot which based on the above equation. The maximum value of Z=0.4(approx) at x=1.Thats why i am saying.
madhan ravi
madhan ravi le 3 Jan 2019
Modifié(e) : madhan ravi le 3 Jan 2019
Perhaps try this with fsolve() :
x=linspace(0,1,101);
Result=cell(1,numel(x));
for i = 1:numel(x)
Result{i}=fsolve(@(z) exp(-10*z)-9*exp(-2*z)+(8-4*x(i)),[-5 5],optimoptions('fsolve','Display','off'));
% ^^---- change it to 0 if you only want the positive roots
end
celldisp(Result)
Note: When plotting the graph two roots were sighted , fsolve is able to find those two roots.
fplot(@(z) exp(-10*z)-9*exp(-2*z)+(8-4*1))
% ^--- from 0 to 1 with 101 points to verify the roots
xlim([-1 1]) % to see the roots clearly
ylim([-1 1])
grid on
See the below graph the two roots can be sighted :
>> Result{end}
ans =
-0.2339 0.4033 % as you said approximately 4 (the positive root)
Screen Shot 2019-01-03 at 9.41.23 AM.png
madhan ravi
madhan ravi le 3 Jan 2019
Modifié(e) : madhan ravi le 3 Jan 2019
@Ravi Singh, See edited answer , if you got the answer to your question make sure to accept the answer else let know of your requirements which part is not clear.
madhan ravi
madhan ravi le 3 Jan 2019
Anytime :)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Mathematics 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!

Translated by