Reputation: 11
#include "StdAfx.h"
#include <math.h>
#include <stdio.h>
#include "pGNUPlotU.h"
int main(void)
{
double N = 5;
double w_c = 2;
double w;
CpGnuplotU plot (_T("C:\\Program Files\\gnuplot\\bin\\wgnuplot.exe"));
FILE *fp = _wfopen (_T("C:\\temp\\1.dat"), _T("wt"));
if (fp) {
for (double w = 0; w < 2; w += 0.01)
{
fwprintf(fp, _T("%f, %f, %f \n"), w, 1 / sqrt(1 + (1 * cos(N * acos(w / w_c)) * cos(N *
acos(w / w_c)))));
}
for (double w = 2; w < 20; w += 0.01)
{
fwprintf(fp, _T("%f, %f, %f \n"), w, 1 / sqrt(1 + (1 * cosh(N * acos(w / w_c)) * cosh(N *
acos(w / w_c)))));
}
fclose (fp);
}
plot.cmd (_T("splot 'C:\\temp\\1.dat' with line"));
getchar();
}
The fomula is about Chebyshev filter. Is there anyone who used gnuplot in c++? the first for statement(w=0; w<2; w+= 0.01) is normally work. I can see the exact graph. But the second for statement(w=2; w<2; w+= 0.01) isn't work. There is nothing on my graph.
What is problem? How can I solve it? I want your answer. Thank You
Upvotes: 0
Views: 136
Reputation: 75062
You put three %f
s in the format specifier, but you give only two data:
w
1 / sqrt(1 + (1 * cosh(N * acos(w / w_c)) * cosh(N * acos(w / w_c))))
to the fwprintf
. This will invoke undefined behavior. You have to give enough number of data to print.
Upvotes: 2