Hey there! Sign in to join this conversationNew here? Join for free
    • Thread Starter
    Offline

    1
    ReputationRep:
    Hello guys,
    I am new member to this site, but I was reading it quite often for some help. But now I am desperate and I need your help. In my class, Programming and algorithm decide that we need to write a working project. Does not sound that hard. But I have no idea what to do it about. It can be whatever I can do, but it must have 3 functions at least and at least 2 of them must have 25 lines of code without comments and must include branching and cycles. More functions can only be additional (simple). In some of the functions must be a non-trivial calculation of mathematical formula. Functions should be connected. (for example, one of the main functions will be using simpler functions for some minor calculations).
    So if i could beg you all. Could you suggest me somethign to write about?
    Because honestly at the moment I am quite lost in it.
    Just one more thing, I am studying Matlab 1st semestr in my uni, so we know just basics. Project itself does not need to have some sort of graphical output, we tried jsut plots. Just simple calculations of some problem.
    Thank you for any sort of help :-)

    EDIT: Sorry for incomplete Thread name, kinda pressed enter by mistake
    Offline

    2
    ReputationRep:
    (Original post by matzas)
    Hello guys,
    I am new member to this site, but I was reading it quite often for some help. But now I am desperate and I need your help. In my class, Programming and algorithm decide that we need to write a working project. Does not sound that hard. But I have no idea what to do it about. It can be whatever I can do, but it must have 3 functions at least and at least 2 of them must have 25 lines of code without comments and must include branching and cycles. More functions can only be additional (simple). In some of the functions must be a non-trivial calculation of mathematical formula. Functions should be connected. (for example, one of the main functions will be using simpler functions for some minor calculations).
    So if i could beg you all. Could you suggest me somethign to write about?
    Because honestly at the moment I am quite lost in it.
    Just one more thing, I am studying Matlab 1st semestr in my uni, so we know just basics. Project itself does not need to have some sort of graphical output, we tried jsut plots. Just simple calculations of some problem.
    Thank you for any sort of help :-)

    EDIT: Sorry for incomplete Thread name, kinda pressed enter by mistake
    You can pretty easily run a lottery simulation on matlab where the user chooses the numbers, then matlab generates 6 numbers from 50 possible ones. Adding a bonus ball or something like that can add a few extra lines of code.

    You can set different responses for different numbers of matched balls, eg if you match everything it can say "yay you win a goat"


    Not the most exciting code in the world, but it gets you used to the basic functions.
    • Thread Starter
    Offline

    1
    ReputationRep:
    Sounds good but I have one question, would it be albe to do 3 functions for this topic? Would 2 of it be for 25 lines? I do not have time to do it atm but I thought of 2 fuctions top + just the 1st one would have more than 25 lines.
    How exacly would you do it? I mean roughtly nothing specific, as you said, and I thought as well, Matlab would generate couple of random numbers, thought of 10. Could I use rand()? problem is that it is generating even decimals (like 3,1241), will need to look if I can just generate numbers like 3,4,6,1 and so on. After user picks his numbers, I guess it would be the variables in function definition. I will need to compare the pick to the generated numbers. I think it would be possible to use if, for or while for it. And in hte end if user found all numbers would see" JACKPOT you won it all!!!" with like just 5 numbers right, something else, could make some output for every number to get more lines.
    What do you think? Do you have any suggestion what to use or something else?
    And to my question at the start, that would be 1st function, what to use as the other 2? It should be something what will work with these results or will be working with something similar like this.
    Offline

    2
    ReputationRep:
    use the randperm function.

    Its ages since i did it and I cant find the file but its something like:

    >A=randperm(1,50);
    >B=sort(A(1:6));

    That might not quite work, but trial and error is generally a good idea in matlab. Try it and see how it works.

    Thats the first 2 functions sorted, now you just need to use another to input the users numbers

    Bonus points for the fourth when you compare the matrices for like terms.
    • Thread Starter
    Offline

    1
    ReputationRep:
    Ok so, I tried that permutation and it worked
    A=randperm(50,10);
    B=sort(A(1:10));
    But you were saying that I already have 2 functions, which one are they? :-)
    Sorry for being a dumb but I am atm a bit confused, I was looking at what I was writing and found only one I know about.
    If you could, please write down every fuction I should know about atm to write.
    1st one should be:
    function x=lottery(guess)
    'guess' will be vector of x numbers user enters.
    then I will enter some sort of A=randperm(50,10); B=sort(A(1:10)); Now I need to add and compare guess to generated numbers. Will need to look how to do it exacly and then it will write down how many times I was right.
    That would be the 1st function

    2nd function could be reward function.
    If you could suggest how to compare generated numbers to my guess, I would gladly appreciate it.
    This function will take the results from the 1st function and with switch could pick the right option and write something as responce.

    3rd function
    I have no idea what to do here.

    EDIT:
    function tip=lottery(g)
    A=randperm(50,10);
    B=sort(A(1:10));
    for i=1:10
    if g(1,i)>50
    disp('Wrong numbers. Numbers must be smaller than 50.')
    end
    end
    Got this while I was waiting for next class. Kinda rethought the 1st and 2nd function.
    Next thing i need to do is make that if person picks more than 10 numbers it will make error.
    Then I need to compare these 2 vectors and write down conclusion. I think it could be done comparing 1 number of my guess with each of the random through cycle then go for the 2nd of my guess and so on.

    2nd function will deal with pure reward system. For each of the point would be cca 3 lines so that's over 30 for all possibilities.

    Still no idea about 3rd function.
    Offline

    2
    ReputationRep:
    I would have a function to generate a 'ticket' (it would need two inputs, a boolean and a vector for random ticket or chosen numbered ticket).
    I would have a function to generate the result numbers and return/display the numbers (this should perhaps be called from within the ticket generation function.
    I would have a function to check if someone won, and calculate their reward. Then display something...

    To be honest, saying you have to write 25 lines of code makes no sense, surely that encourages idiotic code just to make more lines. I mean, say you wanted the 25th entry in a vector, you could write a for loop just to make lines rather than using the direct reference that Matlab provides.
    • Thread Starter
    Offline

    1
    ReputationRep:
    Well yes, I think the need of having at least 25 lines is idiotic, cos honestly I had some Ideas of what to do but they wouldn't be over 25 lines most likely, that's why I came here and ask you guys :-)
    • Thread Starter
    Offline

    1
    ReputationRep:
    Hey guys,
    I need a bit help with my continuing project.
    I finnished the 1st and 2nd over 25 lines functions.
    function tip=lottery(g)
    c=length(g);
    if c==10
    else
    error('Spatna cisla. Musite vybrat presne 10 cisel.')
    end
    g=sort(g(1:10));
    for i=1:10
    if g(1,i)>50
    error('Spatna cisla. Cisla musi byt mensi nez 50.')
    end
    end
    for j=1:9
    if g(1,j)==g(1,j+1)
    error('Spatna cisla. Vsechna cisla musi byt rozdilna.')
    end
    end
    A=randperm(50,10);
    B=sort(A(1:10));
    O=0;
    m=[];
    for k=1:10
    for l=1:10
    o=isequal(g(1,l), B(1,k));
    O=O+o;
    if o==1
    m=[m g(1,l)];
    end
    end
    end
    tip =g;
    z=O/10*100;
    disp (['Uhodnul/a jste ' num2str(O) ' cisla/cisel/cislo, coz je uspesnost ' num2str(z) ' %'])
    disp (['Vase spravne tipnuta cisla jsou: ' num2str(m)])
    save('loterie.mat')

    and 2nd function as reward function
    function spravne
    load ('loterie.mat')
    switch O
    case 0
    disp ('Je nam lito, ale nic nevyhravate')
    case 1
    disp ('Vyhrali jste moznost odejit!')
    case 2
    disp ('Vyhravate 100 litru vzduchu.')
    case 3
    disp ('Dobra prace! Dnes vecer ten rizek ceka na vas.')
    case 4
    disp ('Uz se nekam dostavame! Jen 3 lidi se dostali az sem! Osobne Vam pogratuluju.')
    case 5
    disp ('Polovina spravne! Dostanete polovinu souctu vasich spravne tazenych cisel!')
    case 6
    disp ('Vyhravate 1000 Kc')
    case 7
    disp ('Vyhravate 7000 Kc')
    case 8
    disp ('Vyhravate 18 000 Kc')
    case 9
    disp ('Vyhravate 100 000 Kc')
    case 10
    disp ('JACKPOT!!!! Vyhravate kozu!')
    otherwise
    error('Nekde se stala chyba, prosim tipnete si nova cisla')
    end

    But my problem is that I have no idea what to do as last function. It can be just some dumb idea with 5 lines but should be somehow connected with at least one of these functions, thought of some kinds of statistics but idk how to do it nad if it is even possible. Any ideas? :-)
    Offline

    2
    ReputationRep:
    (Original post by matzas)
    Hey guys,
    I need a bit help with my continuing project.
    I finnished the 1st and 2nd over 25 lines functions.
    If you use
    [code]code tags
    around
    your code[/code]
    it'll preserve indents and look better. Like so:
    Code:
    code tags
    	around
    your code
 
 
 
Reply
Submit reply
TSR Support Team

We have a brilliant team of more than 60 Support Team members looking after discussions on The Student Room, helping to make it a fun, safe and useful place to hang out.

Updated: April 10, 2013
  • See more of what you like on The Student Room

    You can personalise what you see on TSR. Tell us a little about yourself to get started.

  • Poll
    Has a teacher ever helped you cheat?
    Useful resources
  • See more of what you like on The Student Room

    You can personalise what you see on TSR. Tell us a little about yourself to get started.

  • The Student Room, Get Revising and Marked by Teachers are trading names of The Student Room Group Ltd.

    Register Number: 04666380 (England and Wales), VAT No. 806 8067 22 Registered Office: International House, Queens Road, Brighton, BN1 3XE

    Write a reply...
    Reply
    Hide
    Reputation gems: You get these gems as you gain rep from other members for making good contributions and giving helpful advice.