Change a variable till a condition is met
Afficher commentaires plus anciens
Hi, how can i say to matlab to change the variable x till the condition varptf=0 is met? Note that y is (1-x). I did it on excel by analysis tool solver (the solution is rougly x=0.65), idk how to do this on matlab (and for an assignment I have to do this on matlab). Thank you for your time
% point 1
SDa = 0.08 % std of A
SDb = 0.15 % std of B
x = 0 % weight of A
y = 1-x % weight of B
p = -1 % correlation coefficient
varptf = x^2*SDa^2+y^2*SDb^2+2*x*y*p*SDa*SDb
while varptf == 0
x = x+0.01
end
x
Réponse acceptée
Plus de réponses (1)
SDa = 0.08;
SDb = 0.15;
x = 0;
y = 1-x;
p = -1;
varptf =@(x,y)x^2*SDa^2+y^2*SDb^2+2*x*y*p*SDa*SDb;
v=varptf(x,y);
while v>1e-10%~=0 is problematic (unlikely it is going to exactly equal zero)
x=x+.0001;%change additional amount for more accuracy
y=1-x;
v=varptf(x,y);
end
x
Catégories
En savoir plus sur Loops and Conditional Statements dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!