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

 채택된 답변

Star Strider
Star Strider 2021년 3월 9일

0 개 추천

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

Cherin Hamadi
Cherin Hamadi 2021년 3월 10일
This perfectly works. Thanks!
Star Strider
Star Strider 2021년 3월 10일
As always, my pleasure!

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터 및 File Exchange에서 Creating and Concatenating Matrices에 대해 자세히 알아보기

질문:

2021년 3월 9일

댓글:

2021년 3월 10일

Community Treasure Hunt

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

Start Hunting!

Translated by