- #1
Flucky
- 95
- 1
I've basically been set the task below however I've not really been taught how to go about it. I think I know the general theory of how to go about it but the actual commands and putting it all together bamboozles me. The question is attatched.
Just seen the typo, it should be 'loses' not 'looses'. Rookie mistake!
My thinking is that you use the random number feature to get a value between 0 and 1. If it comes out greater than 0.5 it adds a pound (£) to the pot and if it comes out less than 0.5 it removes a £ from the pot (starting off with only £1). You then use the loop feature to continue doing this until/if he reaches £100. However I've not the slightest clue how to measure the probability or even run multiple loops to get an average probability.
The furthest I've got with this problem is:
a=rand % where a is the 50/50 flip
x=1 % where x is the current total amount of money he has
if a<0.5
x=x+1
if a>0.5
x=x-1
end
end
but even when I run that simple script, if the random number comes out less than 0.5 it doesn't remove a £ it just remains at 1.
Any insight on how to solve this would be greatly appreciated as my MATLAB knowledge is poor.
-----------EDIT-------------------------------------------------------------------------------------------
I think I'm getting closer, does this look promising?
Here it stops the script if he runs out of money and also stops when he reaches his target of £100. Now I've hit a wall and don't have a clue how to continue with the question, I haven't even addressed the probability side of it.
Just seen the typo, it should be 'loses' not 'looses'. Rookie mistake!
My thinking is that you use the random number feature to get a value between 0 and 1. If it comes out greater than 0.5 it adds a pound (£) to the pot and if it comes out less than 0.5 it removes a £ from the pot (starting off with only £1). You then use the loop feature to continue doing this until/if he reaches £100. However I've not the slightest clue how to measure the probability or even run multiple loops to get an average probability.
The furthest I've got with this problem is:
a=rand % where a is the 50/50 flip
x=1 % where x is the current total amount of money he has
if a<0.5
x=x+1
if a>0.5
x=x-1
end
end
but even when I run that simple script, if the random number comes out less than 0.5 it doesn't remove a £ it just remains at 1.
Any insight on how to solve this would be greatly appreciated as my MATLAB knowledge is poor.
-----------EDIT-------------------------------------------------------------------------------------------
I think I'm getting closer, does this look promising?
Here it stops the script if he runs out of money and also stops when he reaches his target of £100. Now I've hit a wall and don't have a clue how to continue with the question, I haven't even addressed the probability side of it.
Attachments
Last edited: