|
-
Mar 9th, 2016, 08:10 AM
#1
Thread Starter
New Member
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.
-
Mar 9th, 2016, 08:16 AM
#2
Re: Problem expressing trig function
Show us what you have tried.
-
Mar 9th, 2016, 09:03 AM
#3
Thread Starter
New Member
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"
-
Mar 9th, 2016, 09:10 AM
#4
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
-
Mar 9th, 2016, 09:47 AM
#5
Thread Starter
New Member
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.
-
Mar 9th, 2016, 09:57 AM
#6
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
-
Mar 9th, 2016, 10:15 AM
#7
Thread Starter
New Member
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
-
Mar 9th, 2016, 10:25 AM
#8
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
-
Mar 9th, 2016, 10:29 AM
#9
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
-
Mar 9th, 2016, 10:38 AM
#10
Re: Problem expressing trig function
 Originally Posted by FunkyDexter
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
-
Mar 9th, 2016, 10:46 AM
#11
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
-
Mar 9th, 2016, 10:51 AM
#12
Thread Starter
New Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|