简单的正弦波阵列 [英] Simple Sine Wave Array

查看:142
本文介绍了简单的正弦波阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用数组实现一个基本的正弦波信号,但是我很难(我是一个完整的初学者!)


这是我到目前为止:


使用命名空间std;


双信号(双正弦波,双x);


int main()

{


double x,sinewave,output;

cout<< endl<<"请输入一个值,x"<< endl<< endl;

cin>> x;


输出=信号(正弦波,x);

cout<< endl<<" Sin(x)="<< output<< endl<< endl;


返回0;

}


双信号(双正弦波,双x) )

{


sinewave = sin(x);

返回sinewave;

}


我想交换单个值x,得到100分的数组。


有谁可以帮我这个?


后来,我会的需要改变信号的频率,但是这个现在没关系吗?此外,我想绘制信号,但我认为

这是先进的。


如果有人可以提供帮助,我真的很感激!


Phil Newman

I''m trying to implement a basic sinewave signal using arrays, but I''m
having difficulty (I''m a complete beginner!)

This is what I have so far:

using namespace std;

double signal(double sinewave, double x);

int main()
{

double x, sinewave, output;

cout<<endl<<"Please enter a value, x"<<endl<<endl;
cin>>x;

output = signal(sinewave,x);
cout<<endl<<"Sin(x) = "<<output<<endl<<endl;

return 0;
}

double signal(double sinewave, double x)
{

sinewave = sin(x);
return sinewave;
}

I want to swap a single value x, for an array of 100 points.

Can anyone help me with this?

Later, I''ll need to change the frequency of the signal, but this
doesn''t matter now? Also, I''ll want to plot the signal, but I think
this is advanced.

If anyone can help, I would really appreciated it!

Phil Newman

推荐答案

Phil Newman写道:
Phil Newman wrote:
我正在尝试使用数组实现一个基本的正弦波信号,但我很难(我是一个完全的初学者!)

这就是我到目前为止所拥有的:

使用命名空间std;

双信号(双正弦波,双x);

int main()
{

双x,正弦波,输出;

cout<< endl<<"请输入一个值,x"<<< endl<< endl;
cin>> x;

output = signal(sinewave,x);
cout<< endl<<" Sin(x)="<<输出<<< endl<< endl;

返回0;
}

双信号(双正弦波,双x)
{

sinewave = sin(x);
返回sinewave;
}

我想交换单个值x,得到100分的数组。

任何人都可以帮我这个?

后来,我需要改变信号的频率,但现在这没关系?此外,我想绘制信号,但我认为
这是先进的。

如果有人可以提供帮助,我真的很感激它!

Phil Newman
I''m trying to implement a basic sinewave signal using arrays, but I''m
having difficulty (I''m a complete beginner!)

This is what I have so far:

using namespace std;

double signal(double sinewave, double x);

int main()
{

double x, sinewave, output;

cout<<endl<<"Please enter a value, x"<<endl<<endl;
cin>>x;

output = signal(sinewave,x);
cout<<endl<<"Sin(x) = "<<output<<endl<<endl;

return 0;
}

double signal(double sinewave, double x)
{

sinewave = sin(x);
return sinewave;
}

I want to swap a single value x, for an array of 100 points.

Can anyone help me with this?

Later, I''ll need to change the frequency of the signal, but this
doesn''t matter now? Also, I''ll want to plot the signal, but I think
this is advanced.

If anyone can help, I would really appreciated it!

Phil Newman




试试这个:


#include< iostream>

#include< ; vector>

#include< cmath>


using namespace std;


void FillSin(vector< double>& v)

{

static const double PI = 4 * atan(1.0);

for(int n = 0; n< output.size(); ++ n)

{

v [n] = sin(2 * PI / n);

}

}


int main()

{

vector< double>输出(100);

FillSin(输出);

for(int n = 0; n< output.size(); ++ n)

{

cout<<输出[n]<< ''\ n'';

}

返回0;

}


干杯! --M



Try this:

#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

void FillSin( vector<double>& v )
{
static const double PI = 4*atan(1.0);
for( int n=0; n < output.size(); ++n )
{
v[ n ] = sin( 2*PI / n );
}
}

int main()
{
vector<double> output( 100 );
FillSin( output );
for( int n=0; n < output.size(); ++n )
{
cout << output[n] << ''\n'';
}
return 0;
}

Cheers! --M


mlimber写道:
mlimber wrote:
Phil Newman写道:
Phil Newman wrote:
I我试图用数组实现一个基本的正弦波信号,但是我很难(我是一个初学者!)

这就是我到目前为止所做的: br />
[snip]
我想交换单个值x,得到100分的数组。

任何人都可以帮我这个吗?
<后来,我需要改变信号的频率,但现在这没关系?此外,我想绘制信号,但我认为
这是先进的。

如果有人可以提供帮助,我真的很感激它!

Phil Newman

试试这个:

#include< iostream>
#include< vector>
#include< cmath>

使用命名空间std;

void FillSin(vector< double>& v)
{
static const double PI = 4 * atan(1.0);
for(int n = 0; n< output.size(); ++ n)
{
v [n] = sin(2 * PI / n);
I''m trying to implement a basic sinewave signal using arrays, but I''m
having difficulty (I''m a complete beginner!)

This is what I have so far:

[snip]
I want to swap a single value x, for an array of 100 points.

Can anyone help me with this?

Later, I''ll need to change the frequency of the signal, but this
doesn''t matter now? Also, I''ll want to plot the signal, but I think
this is advanced.

If anyone can help, I would really appreciated it!

Phil Newman

Try this:

#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

void FillSin( vector<double>& v )
{
static const double PI = 4*atan(1.0);
for( int n=0; n < output.size(); ++n )
{
v[ n ] = sin( 2*PI / n );




由零划分!!

}
}

int main()
{
vector< double>输出(100);
FillSin(输出);
for(int n = 0; n< output.size(); ++ n)
{
cout< <输出[n]<< ''\ n'';
}
返回0;
}



Division by Zero !!
}
}

int main()
{
vector<double> output( 100 );
FillSin( output );
for( int n=0; n < output.size(); ++n )
{
cout << output[n] << ''\n'';
}
return 0;
}




Stefan

-

Stefan Naewe

naewe.s_AT_atlas_DOT_de



Stefan
--
Stefan Naewe
naewe.s_AT_atlas_DOT_de


谢谢。不幸的是,代码不会编译。我得到一个错误说:

在函数''void FillSin(std :: vector< double,std :: allocator< double>
Thanks. Unfortunately, the code won''t compile. i get an error saying:
In function ''void FillSin(std::vector<double, std::allocator<double>
&)'':




''输出''未申报


你能在那里帮忙吗?


谢谢,


菲尔



''output'' undeclared

Can you help there?

Thanks,

Phil


这篇关于简单的正弦波阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆