필터 지우기
필터 지우기

ratio using for loops

조회 수: 1 (최근 30일)
Raushan
Raushan 2023년 10월 20일
댓글: Raushan 2023년 10월 21일
I am still trying to solve it.
for s_ast=(0:1:T)
ratio_1=(y_2^(s_ast+1)*(1-y_2^T)*(1-x_2)*epsilon_2^(s_ast+1))/(x_2^(s_ast+1)*(1-x_2^T)*(1-y_2));
ratio_2=((1-y_1^(s_ast+1))*(1-x_1)*epsilon_1^(s_ast+1))/((1-y_1)*((1-x_1^(s_ast+1)+K^(1/gamma)*x_1^T*(1-x_1))));
ratio_tax(s_ast+1)=ratio_1/ratio_2;
if (ratio_tax>1)
s_asterisk_tax=s_ast(end);
else
continue
end
end
disp(s_asterisk_tax);
As suggested, I simplified using geometric series and I excluded when x_1 and x_2, y_1 and y_2 are equal to 0.
However, I am getting s_asterisk_tax wrong.
What is wrong in my code?
Thank you,

채택된 답변

Walter Roberson
Walter Roberson 2023년 10월 20일
편집: Walter Roberson 2023년 10월 20일
if ratio_tax > 1
s_asterisk_tax = s_ast;
break;
end
And make sure you put in protection for the case that you get through all the s_ast values without the ratio ever being > 1.
  댓글 수: 3
Walter Roberson
Walter Roberson 2023년 10월 20일
ratio_satisfied = false;
for s_ast=(0:1:T)
ratio_1=(y_2^(s_ast+1)*(1-y_2^T)*(1-x_2)*epsilon_2^(s_ast+1))/(x_2^(s_ast+1)*(1-x_2^T)*(1-y_2));
ratio_2=((1-y_1^(s_ast+1))*(1-x_1)*epsilon_1^(s_ast+1))/((1-y_1)*((1-x_1^(s_ast+1)+K^(1/gamma)*x_1^T*(1-x_1))));
ratio_tax(s_ast+1)=ratio_1/ratio_2;
if (ratio_tax>1)
s_asterisk_tax = s_ast;
ratio_satisfied = true;
break;
end
end
if ratio_satisfied
disp(s_asterisk_tax);
else
disp('got through all iterations without the ratio being satisfied');
end
Note in particular that you were using s_ast(end) in your assignment to s_asterisk_tax . However, s_ast is the index variable in your for s_ast and as such it is assigned one value at a time. At any time within the for loop, s_ast is a scalar, so it does not make any sense to index s_ast(end) . It is not "wrong" to do so, but it indicates that you are confused about what you are doing, and it confuses people who read the code, so you should avoid the unnecessary (end)
Raushan
Raushan 2023년 10월 21일
Thank you, I got my mistake, I should have (ratio_tax(s_ast+1)<1)

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by