Results 1 to 12 of 12

Thread: Problem expressing trig function

  1. #1

    Thread Starter
    New Member
    Join Date
    Oct 2012
    Location
    Harveyville, PA, US
    Posts
    6

    Problem expressing trig function

    Hi all,

    I'm having a problem writing the trig function H(t) = 2.4 sin (0.017t – 1.377) + 12 in vb.net (or anywhere else for that matter).
    t = day number of year (1-365(6)) and H is the resultant number of daylight hours.

    Thank you, thank you for any help and also for your time.

    Marc M.

  2. #2
    Powered By Medtronic dbasnett's Avatar
    Join Date
    Dec 2007
    Location
    Jefferson City, MO
    Posts
    9,897

    Re: Problem expressing trig function

    Show us what you have tried.
    My First Computer -- Documentation Link (RT?M) -- Using the Debugger -- Prime Number Sieve
    Counting Bits -- Subnet Calculator -- UI Guidelines -- >> SerialPort Answer <<

    "Those who use Application.DoEvents have no idea what it does and those who know what it does never use it." John Wein

  3. #3

    Thread Starter
    New Member
    Join Date
    Oct 2012
    Location
    Harveyville, PA, US
    Posts
    6

    Re: Problem expressing trig function

    Dim H As Single = 0.00
    Dim R As Single = 0.00

    Dim t As Integer = DateTime.Now.DayOfYear
    t = DayOfYr()
    Label1.Text = "Day of year is " & t.ToString
    R = (H(t) = 2.4 Math.sin(0.017t – 1.377) + 12)

    In the last line my error msgs. are for H in (H(t) - "Structure 'Single' cannot be indexed because it has no default property."
    On Math. I get ")" expected
    And on the minus '-' I get "Character is not valid"

  4. #4
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,957

    Re: Problem expressing trig function

    Well the fact that there are two equality operators in that line should give you a clue as to what's wrong. Also, you can't just put two values next to teach other and expect them to be multiplied, you have to supply the multiplication operator (*)

    You probably want this:-
    Code:
    R = 2.4 * Math.sin(0.017 * t – 1.377) + 12
    VB.NET has syntax. Algebra has syntax. They may be similar but they're not the same and you cannot simply cut and paste a formula into VB and expect it to just work.
    The best argument against democracy is a five minute conversation with the average voter - Winston Churchill

    Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd

  5. #5

    Thread Starter
    New Member
    Join Date
    Oct 2012
    Location
    Harveyville, PA, US
    Posts
    6

    Re: Problem expressing trig function

    Yes, I know syntax nearly always have to be converted and I was struggling with this one. I'm not a math ace.



    I'm still getting and errors on the "-" sign: ")" expected. Character is not valid

    I realize the ")" expected can be suspect.

    Note:
    I needed to delete : t = DayOfYr()
    from the example.
    Last edited by mmiller_pa; Mar 9th, 2016 at 09:54 AM.

  6. #6
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,957

    Re: Problem expressing trig function

    I haven't got an ide in front of me to check but I believe what I posted was syntactically correct. 0.017 * t – 1.377 should resolve to some kind of float (probably a double) which is what Math.Sin is expecting. Can you post the code exactly as you have it at present?

    It sounds like you have an extra ( in there somewhere
    The best argument against democracy is a five minute conversation with the average voter - Winston Churchill

    Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd

  7. #7

    Thread Starter
    New Member
    Join Date
    Oct 2012
    Location
    Harveyville, PA, US
    Posts
    6

    Re: Problem expressing trig function

    I get the same err. when I change H and R to Double.



    Dim H As Single = 0.00
    Dim R As Single = 0.00

    Dim t As Integer = DateTime.Now.DayOfYear

    Label1.Text = "Day of year is " & t.ToString
    R = 2.4 * Math.Sin(0.017 * (t – 1.377) + 12

  8. #8
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Problem expressing trig function

    R = 2.4 * Math.Sin(0.017 * (t – 1.377) + 12

    You've got two opening ( but only one closing ) .... is the +12 supposed to be IN the Sin call, or added to the result?

    Never mind... I looked back at post 1... the +12 should be added to the sin result:
    R = 2.4 * Math.Sin(0.017 * (t – 1.377)) + 12

    try that...


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  9. #9
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,957

    Re: Problem expressing trig function

    Count the opening brackets and count the closing brackets. What do you notice?

    Note that I didn't have an opening bracket before t, that's because the formula as you expressed it in post 1 did not have one. By adding that I'm guessing you might me aiming for this:-
    R = 2.4 * Math.Sin(0.017 * (t – 1.377)) + 12

    By wrapping the subtraction in brackets you override the standard order of precedence and force the subtraction to happen before the multiplication. That might be what you want, or you might want the multiplication to happen first which is what was expressed in your original post and is what the code I gave in post 4 will do. I'm afraid I can't tell you which is correct - for that you'd need to understand the formula.

    Edit> Crossed over with TG. @TG, note that the extra brackets are wrapping the subtraction, not the Sin. I'm 99% sure they shouldn't be there at all.
    The best argument against democracy is a five minute conversation with the average voter - Winston Churchill

    Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd

  10. #10
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Problem expressing trig function

    Quote Originally Posted by FunkyDexter View Post
    Count the opening brackets and count the closing brackets. What do you notice?

    Note that I didn't have an opening bracket before t, that's because the formula as you expressed it in post 1 did not have one. By adding that I'm guessing you might me aiming for this:-
    R = 2.4 * Math.Sin(0.017 * (t – 1.377)) + 12

    By wrapping the subtraction in brackets you override the standard order of precedence and force the subtraction to happen before the multiplication. That might be what you want, or you might want the multiplication to happen first which is what was expressed in your original post and is what the code I gave in post 4 will do. I'm afraid I can't tell you which is correct - for that you'd need to understand the formula.

    Edit> Crossed over with TG. @TG, note that the extra brackets are wrapping the subtraction, not the Sin. I'm 99% sure they shouldn't be there at all.
    I always error on the side of caution when it comes to complex expressions... I've been bit by it before.

    What I couldn't figure out is if the equation was supposed to be
    R = 2.4 * Math.Sin(0.017 * (t – 1.377)) + 12
    or
    R = 2.4 * Math.Sin(0.017 * (t – 1.377) + 12)
    until I scrolled back up to the top to post #1... the +12 goes outside the sin call....


    aaaanyways... I also now see what you meant about the order... and I think you're right, the added parens disrupts what it should have been.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  11. #11
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    7,957

    Re: Problem expressing trig function

    If you really want to express the order via parens I think you want:-
    Code:
    R = (2.4 * Math.Sin((0.017 * t) – 1.377)) + 12
    That's the equivalent of the equation in post 1. It's also the equivalent of what I posted in 4.
    The best argument against democracy is a five minute conversation with the average voter - Winston Churchill

    Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd

  12. #12

    Thread Starter
    New Member
    Join Date
    Oct 2012
    Location
    Harveyville, PA, US
    Posts
    6

    Re: Problem expressing trig function

    Thank you for your time and effort. It now works. The error on the minus sign was what I call a speck of fly sh__ in the code. I deleted it and re-entered it and the error disappeared.

    BTW, this calculates the hours of daylight for San Diego, Ca. So, if someone is following this thread, they will have to figure how to adjust the hard coded values.

    Again, thank you!

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width