Beginner question on trigonometry proofs...

Discussion in 'MATLAB' started by Katy, Feb 12, 2006.

  1. Katy

    Katy Guest

    I am new to MATLAB and have yet to find any information on verifying
    trigonometric identities. Namely, how do I make a program that asks a
    user to enter a value of theta in degrees. I believe I need the input
    function for this? Also, the disp function. How do I use a loop
    function for this since I need it to give answers without repeating
    itself. I need my program to verify sin(2theta) =
    2sin(theta)cos(theta) for several values of theta by computing and
    displaying both sides of the equation and the difference between
    them. As I said, I'm new to MATLAB and any help would be appreciated!
     
    Katy, Feb 12, 2006
    #1
    1. Advertisements

  2. Katy

    us Guest

    Katy:
    <SNIP charming little homework problem...

    one of the many solutions

    % copy/paste this section into your command window
    dr=pi/180;
    % exit loop with a CTRL-C sequence
    while true
    thd=input('enter theta in deg < ');
    th=dr*thd;
    eq1=sin(2*th);
    eq2=2*sin(th)*cos(th);
    txt=sprintf([
    'theta %10.3f\n',...
    'eq 1 %30.23f\n',...
    'eq 2 %30.23f\n',...
    'diff %30.23f\n'],...
    thd,eq1,eq2,eq1-eq2);
    disp(txt);
    end

    note that there are FP issues, eg,
    try with 45 and 48
    us
     
    us, Feb 12, 2006
    #2
    1. Advertisements

  3. Katy

    Katy Guest

    Thanks so much! If it wouldn't be too much trouble, could you explain
    what the different steps of code means? I am familiar with assigning
    variables a value but I am not familiar with the portion below
    txt=sprintf. Could I use this same thing for another trigonometric
    proof..of course changing values, etc? Thanks again!
     
    Katy, Feb 12, 2006
    #3
  4. Katy

    us Guest

    Katy:
    <SNIP down to basic questions...
    txt=sprintf(...)

    as this command, typed at the command prompt in the command window as
    shown below

    help sprintf

    shows, the above syntax serves the purpose to write formatted data
    (here: your input and various results) to a char array (also known as
    string), which is ready for display as coded in the snippet

    disp(txt);
    yes
    us
     
    us, Feb 12, 2006
    #4
  5. Katy

    Katy Guest

    Thanks again...I have one more question. I hope you don't mind my
    simple questions. What is the significance of the numbers, dots, and
    f\n,within these rows?
    : 'theta %10.3f\n',...
    and do these numbers change if I were to do this for
    cos(2theta)=(2cos(theta)^2)-1?
     
    Katy, Feb 12, 2006
    #5
  6. Katy

    us Guest

    Katy:
    <SNIP sprintf-formatting trivia...
    according to
    help sprintf
    you see that these numbers aren't but simple instructions on how the
    corresponding data should be turned into a character representation,
    eg, look at this

    disp(sprintf('pi is %f',pi));
    disp(sprintf('pi is %g',pi));
    disp(sprintf('pi is %30.20f',pi));
    disp(sprintf('pi is %s',sprintf('%.10f',pi)));
    % again, scrutinize
    % help sprintf
    % doc sprintf
    cos(2theta)=(2cos(theta)^2)-1...

    no - not necessarily, that is - it all depends on how you want your
    output to look like (eg, precision, additional information for the
    user, etc)
    us
     
    us, Feb 12, 2006
    #6
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.