Effacer les filtres
Effacer les filtres

ratio using for loops

1 vue (au cours des 30 derniers jours)
Raushan
Raushan le 20 Oct 2023
Commenté : Raushan le 21 Oct 2023
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,

Réponse acceptée

Walter Roberson
Walter Roberson le 20 Oct 2023
Modifié(e) : Walter Roberson le 20 Oct 2023
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 commentaires
Walter Roberson
Walter Roberson le 20 Oct 2023
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 le 21 Oct 2023
Thank you, I got my mistake, I should have (ratio_tax(s_ast+1)<1)

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by