Java application 1: Obtain the sample value from the sampling function and store it in the txt document.
Import java. io. *; public class Data {public static void main (String [] args) {try {BufferedOutputStream out = new BufferedOutputStream (new FileOutputStream ("data.txt ")); stringBuilder sb = new StringBuilder (""); float f; String _ f; float t = 0; String _ t; int flag = 1; System. out. print ("Steps \ t"); System. out. print ("time \ t"); System. out. print ("force \ t"); System. out. println (); sb. append ("Steps" + "\ t"); sb. append ("time" + "\ t"); sb. append ("force" + "\ t"); sb. append ("\ r \ n"); for (flag = 1; flag <= 30000;) {f = (float) (100 * Math. sin (2 * Math. PI * t) + 2000); _ f = String. format ("%. 2f ", f); _ t = String. format ("%. 4f ", t); System. out. print (flag + "\ t"); System. out. print (_ t + "\ t"); System. out. print (_ f + "\ t"); System. out. println (); sb. append (flag + "\ t"); sb. append (_ t + "\ t"); sb. append (_ f + "\ t"); sb. append ("\ r \ n"); // modify the interval t = (float) (t + 0.0128); flag ++;} String a = sb. toString (); byte [] B = (). getBytes (); out. write (B, 0, B. length); out. close () ;}catch (Exception e ){}}}
The sampling function is
f = (float)(100*Math.sin(2*Math.PI*t)+2000);
The result is that the txt text contains 30 thousand pieces of data, as shown below:
<喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink">
VcHJlPjxwcmUgY2xhc3M9 "brush: java;"> after running the program, 30000 values are automatically generated on the desktop of the computer. This case can be used for data collection.