Sine wave Generation
I am working on a project that I want to output a sine wave of 50Hertz. I have defined it as follows:
`float amplitude = 10.0f;
float frequency = 50.0f;
//float phase = 0.0f;
float samples = 150.0f;
for (int t = 0; t<samples; t++)
{
float wt = (float)(amplitude * Math.Sin((2.0f * Math.PI * frequency * t /
samples)));``
}`
When I run the code I am not getting the expected results when I plot the values on a graph. Does any one know if I am doing this right or what my problem is. Thanks
See also questions close to this topic

Csharp how to handle multiple game lobbies in unity?
I've got a 1v1's game and currently writing a UDP server. I want physics to be calculated server side, but there will be many instances running.. How to do this?

c#  Initialize a List<Double[]> with single dimension and 3 elements
I have tried many tutorials but none seem to work in this case. I need a
List<Double[3]>
But don't seem to be able to come up with the right syntax. I have tried:List<double[]> points = new List<double> {0.0, 0.0, 0.0 }; List<double[3]> points = new List<double> {0.0, 0.0, 0.0 }; List<double[]> points = new List<double[]> {};
Later on I am doing:
pointDouble[0] = Convert.ToDouble(pointString[0]); pointDouble[1] = Convert.ToDouble(pointString[1]); pointDouble[2] = Convert.ToDouble(pointString[2]); points.Add(pointDouble);
If I get the initialization to work then I get a mismatch when I try to add the pointDouble[] to the list. Usually the message that double[] cannot be converted to Double.

Npgsql: prepared statement "_p1" does not exist
I am trying to load EOD stock data into a table using this method:
public async Task<long> BulkInsertEodData(IEnumerable<EodData> records, string symbol) { var recordsProcessed = 0L; using (var conn = await OpenConnection()) using (var trans = conn.BeginTransaction()) using (var comm = _factory.CreateCommand()) { try { comm.Connection = conn; comm.Transaction = trans; comm.CommandText = INSERT_EOD; var ps = AddParametersToInsertEodQuery(comm); foreach (var p in ps) comm.Parameters.Add(p); comm.Prepare(); foreach (var record in records) { comm.Parameters["@date_id"].Value = record.DateId; comm.Parameters["@symbol"].Value = symbol.ToUpper(); comm.Parameters["@eod_close"].Value = record.EodClose; comm.Parameters["@eod_high"].Value = record.EodHigh; comm.Parameters["@eod_low"].Value = record.EodLow; comm.Parameters["@eod_volume"].Value = record.EodVolume; comm.Parameters["@eod_open"].Value = record.EodOpen; comm.Parameters["@eod_split"].Value = record.EodSplit; comm.Parameters["@eod_dividend"].Value = record.EodDividend; comm.Parameters["@last_modified"].Value = DateTime.UtcNow; await comm.ExecuteNonQueryAsync(); recordsProcessed++; } trans.Commit(); } catch (Exception ex) { _logger.LogError(ex, "BulkInsertEodData(IEnumerable<EodData>)"); trans.Rollback(); } } return recordsProcessed; }
The query text is as follows:
INSERT INTO public.eod_datas( date_id, stock_id, eod_open, eod_close, eod_low, eod_high, eod_volume, eod_dividend, eod_split, last_modified_timestamp ) values @date_id, (select s.id from stocks s where s.symbol = @symbol limit 1), @eod_open, @eod_clos, @eod_low, @eod_high, @eod_volume, @eod_dividend, @eod_split, current_timestamp on conflict (date_id, stock_id) do update set eod_open = @eod_open, eod_close = @eod_close, eod_low = @eod_low, eod_high = @eod_high, eod_volume = @eod_volume, eod_dividend = @eod_dividend, eod_split = @eod_split, last_modified_timestamp = current_timestamp;
It's not my first rodeo with prepared statements, but I am doing a couple things different this time around (.NET Core, using DbProviderFactory) and I'm getting odd results.
The first couple of times through this method, I get an error to the effect of
Npgsql.PostgresException (0x80004005): 42601: syntax error at or near "$1"
which is fairly mystifying in itself but the most mysterious of all is that the error actually goes away after a couple of method calls, and I start gettingNpgsql.PostgresException (0x80004005): 26000: prepared statement "_p1" does not exist
consistently afterwords.Can someone explain this behavior? What am I doing wrong? Where do I get more details into what "$1" is all about?

Wrong asin result
My code:
import math x = input() print(math.asin(math.radians(float(x))))
My x was 0.7071067811865475, and the result was some irracional number between 0 and 1, but in my knowledge it should have been around 45

Trigonometric functions approximation using deep learning
Is it possible to use deep learning to approximate trigonometric functions ?
I have used this code. It only got me a horizontal line (y=0). Is there any way to make it vary like sin function?
def f(x): return sin(x) t = arange(0.0, 1.0, 0.01) y = f(t) model=Sequential() model.add(Dense(512,input_shape=(1,), activation='relu')) model.add(Dense(256, activation='linear')) model.add(Dense(128, activation='relu')) model.add(Dense(64, activation='relu')) model.add(Dense(32, activation='relu')) model.add(Dense(16, activation='relu')) model.add(Dense(8, activation='relu')) model.add(Dense(4, activation='relu')) model.add(Dense(1, activation='softplus')) model.compile(optimizer='adam', loss='mean_absolute_percentage_error', metrics=['accuracy']) model.fit(t,y, epochs=75000,batch_size=10) def fit(t): return model.predict(t)

c++ trigonometric function returns unexpected value
I've been assigned to write a program that takes an int or a float in degrees as input and returns the
sin
andcos
of that value with 6 decimal places. But when the input is 90 and 180 I get weird negative zeros, instead of "positive" zeros.Code:
#include <iostream> #include <cmath> #include <iomanip> using namespace std; const double PI = 3.14159265; int main() { float x; cin >> x; x = x * PI / 180; cout << fixed; cout << setprecision(6) << sin(x); cout << ' ' << setprecision(6) << cos(x) << endl; }
Undesired Input and output:
In:90 Out:1.000000 0.000000 In:180 Out:0.000000 1.000000
I've tried to fix this by multiplying the result of the cos function by 1 when the input is 90 but it still outputs 0.000000.
Solution: As @harold and @user2618142 pointed out, the result of the calculation was negative, so the approximation returned a negative 0.