I have the following parameters and function and I need to write a code solving for one variable.
Parameters:
Theta = 0.82
Alph= 0.27
D_x is a vector with 20 points (0-1.05)
The equation is
D_x= theta*x+(1-theta)* (x^(1-alpha))
I want to solve for x that corresponds to each point in D_x vector. Please let me know if you can help with this.
Thanks,
Cherin

 Akzeptierte Antwort

Star Strider
Star Strider am 9 Mär. 2021

0 Stimmen

Try this:
theta = 0.82
alpha = 0.27
D_x = linspace(0, 1.05, 20);
D_x_fcn = @(x) theta*x+(1-theta).*(x.^(1-alpha));
for k = 1:numel(D_x)
xv(k) = fsolve(@(x) D_x(k) - D_x_fcn(x), 1);
end
Results = table(D_x(:), xv(:), 'VariableNames',{'D_x','x'})
producing:
D_x x
________ ________
0 0
0.055263 0.04469
0.11053 0.095319
0.16579 0.14781
0.22105 0.20143
0.27632 0.25583
0.33158 0.31083
0.38684 0.3663
0.44211 0.42218
0.49737 0.4784
0.55263 0.53491
0.60789 0.59168
0.66316 0.64868
0.71842 0.70589
0.77368 0.76329
0.82895 0.82086
0.88421 0.87859
0.93947 0.93646
0.99474 0.99447
1.05 1.0526
Note that fzero has problems with this, the reason I went with fsolve.

2 Kommentare

Cherin Hamadi
Cherin Hamadi am 10 Mär. 2021
This perfectly works. Thanks!
Star Strider
Star Strider am 10 Mär. 2021
As always, my pleasure!

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Community Treasure Hunt

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

Start Hunting!

Translated by