ratio using for loops

1 visualización (últimos 30 días)
Raushan
Raushan el 20 de Oct. de 2023
Comentada: Raushan el 21 de Oct. de 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,

Respuesta aceptada

Walter Roberson
Walter Roberson el 20 de Oct. de 2023
Editada: Walter Roberson el 20 de Oct. de 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 comentarios
Walter Roberson
Walter Roberson el 20 de Oct. de 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 el 21 de Oct. de 2023
Thank you, I got my mistake, I should have (ratio_tax(s_ast+1)<1)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Mathematics en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by