未验证 提交 d67237a0 编写于 作者: H Hypo 提交者: GitHub

Merge pull request #1 from Eddie-He-090/Future

Future
# 数字信号处理综合设计实验2019-2020
n=1;
f1=100; f2=300;
fs=1000;%采样频率?
t=0:1/fs:n;
fre=10;
y1=square(2*fre*pi*t)/2;
y2=square(2*fre*pi*t)/2;
dt=1/fs;%定义时间步长?
n1=length(t);%样点个数?
f_end=1/dt;%频率轴的显示范围?
f=(0:n1-1)*f_end/n1-f_end/2;%频率自变量?
Xf1=dt*fftshift(fft(y1));%频谱?
Xf2=dt*fftshift(fft(y2));
figure(1);
subplot(211);plot(t,y1);xlabel('t');title('基带信号时域图');
subplot(212);plot(f,abs(Xf1));xlabel('f');title('基带信号频谱');
z1=1*sin(2*pi*f1*t);
z2=1*sin(2*pi*f2*t);
figure(2);
subplot(221);plot(t,z1);xlabel('t');title('100Hz正弦波时域图');
subplot(222);plot(f,abs(dt*fftshift(fft(z1))));xlabel('f');title('100Hz正弦波幅度频谱');
subplot(223);plot(t,z2);xlabel('t');title('300Hz正弦波时域图');
subplot(224);plot(f,abs(dt*fftshift(fft(z2))));xlabel('f');title('300Hz正弦波幅度频谱');
yy1=y1.*z1;%信号相乘?
yy2=y2.*z2;
yy3=yy1+yy2;
Xf3=dt*fftshift(fft(yy1));
figure(3);
subplot(411);plot(t,yy1);xlabel('t');title('调制信号1时域');
subplot(412);plot(f,abs(Xf3));xlabel('f');title('调制信号1频谱');
Xf4=dt*fftshift(fft(yy2));
figure(3);
subplot(413);plot(t,yy2);xlabel('t');title('调制信号2时域');
subplot(414);plot(f,abs(Xf4));xlabel('f');title('调制信号2频谱');
Xf5=dt*fftshift(fft(yy3));
figure(4);
subplot(211);plot(t,yy3);xlabel('t');title('调制信号1+2时域');
subplot(212);plot(f,abs(Xf5));xlabel('f');title('调制信号1+2频谱');
fp1=50;fp2=150;%FIR滤波器100Hz?
fs1=0;fs2=200;
As=15;
Ws1=(fp1+fs1)/fs; Ws2=(fp2+fs2)/fs;
w=(fp1-fs1)/fs;
M=ceil((As-7.95)/(14.36*w));
H=hamming(M+1);
b=fir1(M,[Ws1,Ws2],H);
% figure(5);
% freqz(b,1,fs,fs);title('FIR滤波器50-150Hz');
t=0:1/fs:n;
yyy1=filter(b,2,yy3);%信号1+2经过滤波器1?
% zz1=filter(b,2,z1);%100Hz正弦波经过滤波器1
Xf10=dt*fftshift(fft(yyy1)); Xf11=dt*fftshift(fft(zz1));
figure(7);
subplot(411);plot(t,yyy1);xlabel('t');title('信号1+2经滤波器1后时域图');
subplot(412);plot(f,abs(Xf10));xlabel('f');title('信号1+2经滤波器1后频谱');
% figure(8);
% subplot(212);plot(f,abs(zz1));xlabel('f');title('100Hz正弦波滤波器1后频谱');
% subplot(212);plot(f,abs(zz1));xlabel('f');title('100Hz正弦波滤波器1后频谱');
fp1=250;fp2=350;%FIR滤波器300Hz?
fs1=200;fs2=400;
As=15;
Ws1=(fp1+fs1)/fs; Ws2=(fp2+fs2)/fs;
w=(fp1-fs1)/fs;
M=ceil((As-7.95)/(14.36*w));
H2=hamming(M+1);
b=fir1(M,[Ws1,Ws2],H2);
% figure(9);
% freqz(b,1,fs,fs);title('FIR滤波器250-350Hz');
t=0:1/fs:n;
yyy2=filter(b,2,yy3);
% zz2=filter(b,2,z2);
Xf12=dt*fftshift(fft(yyy2));
Xf13=dt*fftshift(fft(zz2));
figure(7);
subplot(413);plot(t,yyy2);xlabel('t');title('信号1+2经滤波器2后时域图');
subplot(414);plot(f,abs(Xf12));xlabel('f');title('信号1+2经滤波器2后频谱');
% figure(11);
% subplot(211);plot(t,zz2);xlabel('t');title('300Hz正弦波滤波器2后时域图');
% subplot(212);plot(f,abs(zz2));xlabel('f');title('300Hz正弦波滤波器2后频谱');
k1=yyy1.*z1;%解调?
k2=yyy2.*z2;
% figure(12);
% subplot(211);plot(t,k1);xlabel('t');title('解调信号1时域图');
% subplot(212);plot(f,abs(dt*fftshift(fft(k1))));xlabel('f');title('解调信号1频谱');
% figure(13);
% subplot(211);plot(t,k2);xlabel('t');title('解调信号2时域图');
% subplot(212);plot(f,abs(dt*fftshift(fft(k2))));xlabel('f');title('解调信号2频谱');
N=8;%8阶巴特沃斯低通滤波器上限频率100Hz?
Wn=100/(fs/2);
[b,a]=butter(N,Wn,'low');
kk1=filter(b,a,k1);
kk2=filter(b,a,k2);
% figure(14);
[H,W]=freqz(b,a);%返回频率响应
% subplot(211);plot(W*fs/(2*pi),abs(H));xlabel('频率Hz');ylabel('幅值');
% grid on;
% subplot(212);plot(W*fs/(2*pi),20*log10(abs(H)));xlabel('频率Hz');ylabel('幅值dB');
% grid on;
Xf6=dt*fftshift(fft(kk1));
Xf7=dt*fftshift(fft(kk2));
figure(15);
subplot(211);plot(t,kk1);xlabel('t');title('解调信号1经滤波时域');
subplot(212);plot(f,abs(Xf6));xlabel('f');title('解调信号1经滤波频谱');
figure(16);
subplot(211);plot(t,kk2);xlabel('t');title('解调信号2经滤波时域');
subplot(212);plot(f,abs(Xf7));xlabel('f');title('解调信号2经滤波频谱');
\ No newline at end of file
#include "Includes.h" /* uC/OS interface */
#include "option.h"
#include "2410lib.h"
#include "uhal.h"
OS_STK StackLED[STACKSIZE]= {0, };
OS_STK StackSEG[STACKSIZE]= {0, };
char IdLED = '1';
char IdSEG = '2';
int seg=0;
void TaskLED(void *Id);
void TaskSEG(void *Id);
OS_EVENT *Mbox1;
void User_LED_Blink(void)
{
static int led_status = 1;
led_status += 1;
if(led_status % 2 == 0)
Led_Display(0x0f);
else
Led_Display(0x00);
}
void User_SEG_Blink(void)
{
static unsigned char seg_value[] = { 0xc0, 0xf9, 0xa4, 0xb0, 0x99, 0x92, 0x82, 0xf8, 0x80, 0x90, 0x88, 0x83, 0xc6, 0xa1, 0x86, 0x8e };
static int seg_status = 0;
*((unsigned char *)0x10000006) = 0x3e;
*((unsigned char *)0x10000004) = seg_value[seg];
seg_status += 1;
if(seg_status > 15)
seg_status = 0;
}
void TaskLED(void *Id)
{
char Msg[100];
INT8U err;
int nCount = 0;
int benable = STEP_MOTOR_ENABLE;
int direct = STEP_MOTOR_CLOCKWISE;
char led_status = 0x0;
ARMTargetStart();
uHALr_printf("Task1() called\n");
uHALr_printf("步进电机测试!\n");
uHALr_printf("E -- 正反转 F -- 启停");
uHALr_printf("UP -- 加速 DOWN -- 减速");
DRVStepperInit();
DRVStepperSetDirect(direct);
DRVStepperControl(benable);
for (;;) {
INT8U ch;
ch = Key_GetKey();
if(ch == 0)
continue;
switch( ch )
{
case '1':
uHALr_printf("\r1");
seg=1;
sprintf(Msg, "TaskSEG %d", nCount++);
OSMboxPost(Mbox1, Msg);
break;
case '2':
uHALr_printf("\r2\r");
seg=2;
sprintf(Msg, "TaskSEG %d", nCount++);
OSMboxPost(Mbox1, Msg);
break;
case '3':
uHALr_printf("\r3\r");
seg=3;
sprintf(Msg, "TaskSEG %d", nCount++);
OSMboxPost(Mbox1, Msg);
break;
case '4':
uHALr_printf("\r4\r");
seg=4;
sprintf(Msg, "TaskSEG %d", nCount++);
OSMboxPost(Mbox1, Msg);
break;
case '5':
uHALr_printf("\r5\r");
seg=5;
sprintf(Msg, "TaskSEG %d", nCount++);
OSMboxPost(Mbox1, Msg);
break;
case '6':
uHALr_printf("\r6\r");
seg=6;
sprintf(Msg, "TaskSEG %d", nCount++);
OSMboxPost(Mbox1, Msg);
break;
case '7':
uHALr_printf("\r7\r");
seg=7;
sprintf(Msg, "TaskSEG %d", nCount++);
OSMboxPost(Mbox1, Msg);
break;
case '8':
uHALr_printf("\r8\r");
seg=8;
sprintf(Msg, "TaskSEG %d", nCount++);
OSMboxPost(Mbox1, Msg);
break;
case '9':
uHALr_printf("\r9\r");
seg=9;
sprintf(Msg, "TaskSEG %d", nCount++);
OSMboxPost(Mbox1, Msg);
break;
case '0':
uHALr_printf("\r0\n");
seg=0;
sprintf(Msg, "TaskSEG %d", nCount++);
OSMboxPost(Mbox1, Msg);
break;
case 'A':
uHALr_printf("\rA\n");
User_LED_Blink();
seg=10;
sprintf(Msg, "TaskSEG %d", nCount++);
OSMboxPost(Mbox1, Msg);
break;
case 'C':
uHALr_printf("\r加速");
DRVStepperSpeedUp();
seg=12;
sprintf(Msg, "TaskSEG %d", nCount++);
OSMboxPost(Mbox1, Msg);
break;
case 'D':
uHALr_printf("\r减速");
DRVStepperSpeedDown();
seg=13;
sprintf(Msg, "TaskSEG %d", nCount++);
OSMboxPost(Mbox1, Msg);
break;
case 'E':
if(direct == STEP_MOTOR_CLOCKWISE)
{
uHALr_printf("\r正转");
direct = STEP_MOTOR_ANTICLOCKWISE;
seg=14;
sprintf(Msg, "TaskSEG %d", nCount++);
OSMboxPost(Mbox1, Msg);
}
else
{
uHALr_printf("\r反转");
direct = STEP_MOTOR_CLOCKWISE;
seg=14;
sprintf(Msg, "TaskSEG %d", nCount++);
OSMboxPost(Mbox1, Msg);
}
DRVStepperSetDirect(direct);
break;
case 'F':
if(benable == STEP_MOTOR_ENABLE)
{
uHALr_printf("\r停止ֹ");
benable = STEP_MOTOR_DISABLE;
seg=15;
sprintf(Msg, "TaskSEG %d", nCount++);
OSMboxPost(Mbox1, Msg);
}
else
{
uHALr_printf("\r启动");
benable = STEP_MOTOR_ENABLE;
seg=15;
sprintf(Msg, "TaskSEG %d", nCount++);
OSMboxPost(Mbox1, Msg);
}
DRVStepperControl(benable);
break;
}
OSTimeDly(10);
}
}
void TaskSEG(void *Id)
{
char *Msg;
INT8U err;
for (;;) {
Msg = (char *)OSMboxPend(Mbox1, 0, &err);
uHALr_printf("Task2() called\n");
OSSchedLock();
sprintf(print_buf, "Task%c() turned\n", *(char *)Id);
uHALr_printf(print_buf);
User_SEG_Blink();
OSSchedUnlock();
OSTimeDly(10);
}
}
void Main(void)
{
ARMTargetInit();
OSInit();
Mbox1 = OSMboxCreate((void *)0);
OSTaskCreate(TaskLED, (void *)&IdLED, (OS_STK *)&StackLED[STACKSIZE - 1], 5);
OSTaskCreate(TaskSEG, (void *)&IdSEG, (OS_STK *)&StackSEG[STACKSIZE - 1], 13);
OSStart();
return;
}
# 嵌入式综合设计实验
Java2019-2020没有考试,成绩由sort排序作业、期中类之间的调用作业、期末大作业共同决定
Github上传速度极慢,所以只上传.Java文件和报告,要使用时用IED创建一个空白工程把代码复制过去即可
import java.util.Arrays;
//import java.util.Random;
public class Sorts {
public static void main(String[] args) {
int score[] = new int[1000];
System.out.println("\n排序前数组内容如下:");
for (int k = 0; k < score.length; k++) {
score[k] = (int) (Math.random() * 1001);
System.out.print(score[k] + "\t");
}
int scores1[]= new int[1000];
int scores2[]= new int[1000];
int scores3[]= new int[1000];
int scores4[]= new int[1000];
//scores1 = score;
//scores2 = score;
//scores3 = score;
//scores4 = score;
for (int k = 0; k < scores4.length; k++) {
scores4[k] = (int) (Math.random() * 1001);
//System.out.print(scores4[k] + "\t");
}
for (int k = 0; k < scores3.length; k++) {
scores3[k] = (int) (Math.random() * 1001);
//System.out.print(scores3[k] + "\t");
}
for (int k = 0; k < scores2.length; k++) {
scores2[k] = (int) (Math.random() * 1001);
//System.out.print(scores2[k] + "\t");
}
for (int k = 0; k < scores1.length; k++) {
scores1[k] = (int) (Math.random() * 1001);
//System.out.print(scores1[k] + "\t");
}
//int scores4[] = { 77, 55, 88, 99, 66, 11, 33, 44, 22 }; // 定义含有5个元素的数组
long start4 = System.currentTimeMillis();
for (int i = 0; i < scores4.length; i++) { // 插入排序
for (int j = i; j > 0; j--) {
if (scores4[j] < scores4[j - 1]) {
int temp = scores4[j];
scores4[j] = scores4[j - 1];
scores4[j - 1] = temp;
}
else {
break;
}
}
}
long end4 = System.currentTimeMillis();
System.out.println("\n插入排序后的数组内容如下:");
for (int j = 0; j < scores4.length; j++) // 遍历排序后的数组
{
System.out.print(scores4[j] + "\t");
}
System.out.println("\n插入排序运算时间为");
System.out.println(end4 - start4);
//int scores2[] = { 77, 55, 88, 99, 66, 11, 33, 44, 22 }; // 定义含有5个元素的数组
long start2 = System.currentTimeMillis();
for (int i = 0; i < scores2.length - 1; i++) { // 选择排序
for (int j = i + 1; j < scores2.length; j++) {
if (scores2[i] > scores2[j]) {
int temp = scores2[i];
scores2[i] = scores2[j];
scores2[j] = temp;
}
}
}
long end2 = System.currentTimeMillis();
System.out.println("\n选择排序后的数组内容如下:");
for (int j = 0; j < scores2.length; j++) // 遍历排序后的数组
{
System.out.print(scores2[j] + "\t");
}
System.out.println("\n选择排序运算时间为");
System.out.println(end2 - start2);
//int scores3[] = { 77, 55, 88, 99, 66, 11, 33, 44, 22 }; // 定义含有5个元素的数组
long start3 = System.currentTimeMillis();
for (int i = 0; i < scores3.length - 1; i++) { // 冒泡排序
for (int j = 0; j < scores3.length - 1 - i; j++) {
if (scores3[j] > scores3[j + 1]) {
int temp = scores3[j];
scores3[j] = scores3[j + 1];
scores3[j + 1] = temp;
}
}
}
long end3 = System.currentTimeMillis();
System.out.println("\n冒泡排序后的数组内容如下:");
for (int j = 0; j < scores3.length; j++) // 遍历排序后的数组
{
System.out.print(scores3[j] + "\t");
}
System.out.println("\n冒泡排序运算时间为");
System.out.println(end3 - start3);
System.out.println("\nsort排序前数组内容如下:");
for (int i = 0; i < scores1.length; i++)// 对score数组进行循环遍历
{
System.out.print(scores1[i] + "\t");
}
System.out.println("\nsort排序后的数组内容如下:");
long start1 = System.currentTimeMillis();
Arrays.sort(scores1); // 对数组进行排序
long end1 = System.currentTimeMillis();
for (int j = 0; j < scores1.length; j++) // 遍历排序后的数组
{
System.out.print(scores1[j] + "\t");
}
System.out.println("\nsort运算时间为");
System.out.println(end1 - start1);
System.out.println("\nsort运算时间为");
System.out.println(end1 - start1);
System.out.println("选择排序运算时间为");
System.out.println(end2 - start2);
System.out.println("冒泡排序运算时间为");
System.out.println(end3 - start3);
System.out.println("插入排序运算时间为");
System.out.println(end4 - start4);
}
}
\ No newline at end of file
package com.company;
import com.company.Goods;
public class Clothes extends Goods {
private String Designer;
private String Size;
public void Set_Designer(String temp4) {
Designer = temp4;
}
public void Set_Size(String temp5) {
Size = temp5;
}
public String Get_Designer() {
return Designer;
}
public String Get_Size() {
return Size;
}
// public void Show() {
// System.out.println("ID:" + Clothes.Get_Name());
// System.out.println("Name:" + Clothes.Get_Name());
// System.out.println("Price:" + Clothes.Get_Price);
// System.out.println("Among:" + Clothes.Get_Among);
// System.out.println("Designer:" + Clothes.Get_Designer);
// System.out.println("Size" + Clothes.Get_Size);
// }
}
package com.company;
public class Goods {
private int ID;
private String Category;
private int Price;
private int Among;
public void Set_ID(int temp0) {
ID = temp0;
}
public void Set_Category(String temp1) {
Category = temp1;
}
public void Set_Price(int temp2) {
Price = temp2;
}
public void Set_Among(int temp3) {
Among = temp3;
}
public void Set_Among() {
Among = Among+1;
}
public int Get_ID() {
return ID;
}
public String Get_Category() {
return Category;
}
public int Get_Price() {
return Price;
}
public int Get_Among() {
return Among;
}
}
package com.company;
import com.company.Goods;
public class Laptops extends Goods {
private String CPU;
private String ScreenSize;
public void Set_CPU(String temp6) {
CPU = temp6;
}
public void Set_ScreenSize(String temp7) {
ScreenSize = temp7;
}
public String Get_CPU() {
return CPU;
}
public String Get_ScreenSize() {
return ScreenSize;
}
}
package com.company;
import java.util.Scanner;
import java.io.IOException;
import java.util.Scanner;
import com.company.*;
public class Main {
Goods List0 = new Goods();
public int Check() {
return List0.Get_ID();
}
public void GetList() {
System.out.println();
System.out.println("------------------------------");
System.out.println("ID: " + List0.Get_ID());
System.out.println("Category: " + List0.Get_Category());
System.out.println("Price: " + List0.Get_Price());
System.out.println("Among: " + List0.Get_Among());
System.out.println("------------------------------");
}
public void AddList_Clothes1() {
List0.Set_ID(1);
List0.Set_Category("Clothes");
List0.Set_Price(1000);
List0.Set_Among();
}
public void AddList_Laptops1() {
List0.Set_ID(3);
List0.Set_Category("Laptops");
List0.Set_Price(3000);
List0.Set_Among();
}
public void AddList_Laptops2() {
List0.Set_ID(4);
List0.Set_Category("Laptops");
List0.Set_Price(4000);
List0.Set_Among();
}
public void DeleteList() {
List0.Set_ID(0);
List0.Set_Category(null);
List0.Set_Price(0);
List0.Set_Among(0);
}
public int CheckList() {
int x, y, z;
x = List0.Get_Among();
y = List0.Get_Price();
z = x * y;
return z;
}
public static void main(String[] args) {
// write your code here
Scanner scanner = new Scanner(System.in);
Clothes clothes1 = new Clothes();
Clothes clothes2 = new Clothes();
Laptops laptops1 = new Laptops();
Laptops laptops2 = new Laptops();
Main List1 = new Main();
Main List2 = new Main();
Main List3 = new Main();
clothes1.Set_ID(1);
clothes1.Set_Category("Clothes");
clothes1.Set_Price(1000);
clothes1.Set_Designer("Jimmy");
clothes1.Set_Size("S,M,L");
clothes2.Set_ID(2);
clothes2.Set_Category("Clothes");
clothes2.Set_Price(2000);
clothes2.Set_Designer("Ben");
clothes2.Set_Size("M,L,XL");
laptops1.Set_ID(3);
laptops1.Set_Category("Laptops");
laptops1.Set_Price(3000);
laptops1.Set_CPU("Intel");
laptops1.Set_ScreenSize("13.3");
laptops2.Set_ID(4);
laptops2.Set_Category("Laptops");
laptops2.Set_Price(4000);
laptops2.Set_CPU("AMD");
laptops2.Set_ScreenSize("15.6");
while (true) {
System.out.println("------------------------------");
System.out.println("Hello,please imput a digit");
System.out.println("1-显示购物清单");
System.out.println("2-显示物品列表");
System.out.println("3-添加商品");
System.out.println("4-清空购物车");
System.out.println("5-结算");
int Digit = scanner.nextInt();
if (Digit == 1) {
if (List1.Check() == 0 || List1.Check() == 1 || List1.Check() == 3 || List1.Check() == 4)
if (List2.Check() == 0)
List1.GetList();
else if (List3.Check() == 0) {
List1.GetList();
List2.GetList();
} else {
List1.GetList();
List2.GetList();
List3.GetList();
}
}
if (Digit == 2) {
System.out.println();
System.out.println("------------------------------");
System.out.println("ID: " + clothes1.Get_ID());
System.out.println("Category: " + clothes1.Get_Category());
System.out.println("Price: " + clothes1.Get_Price());
System.out.println("Designer: " + clothes1.Get_Designer());
System.out.println("Size: " + clothes1.Get_Size());
System.out.println();
System.out.println("ID: " + laptops1.Get_ID());
System.out.println("Category: " + laptops1.Get_Category());
System.out.println("Price: " + laptops1.Get_Price());
System.out.println("Designer: " + laptops1.Get_CPU());
System.out.println("Size: " + laptops1.Get_ScreenSize());
System.out.println();
System.out.println("ID: " + laptops2.Get_ID());
System.out.println("Category: " + laptops2.Get_Category());
System.out.println("Price: " + laptops2.Get_Price());
System.out.println("Designer: " + laptops2.Get_CPU());
System.out.println("Size: " + laptops2.Get_ScreenSize());
System.out.println("------------------------------");
}
if (Digit == 3) {
System.out.println("输入商品ID");
int temp8 = scanner.nextInt();
if (temp8 == clothes1.Get_ID()) {
if (List1.Check() == clothes1.Get_ID() || List1.Check() == 0) {
List1.AddList_Clothes1();
System.out.println("Succeed");
} else if (List2.Check() == clothes1.Get_ID() || List2.Check() == 0) {
List2.AddList_Clothes1();
System.out.println("Succeed");
} else {
List3.AddList_Clothes1();
System.out.println("Succeed");
}
} else if (temp8 == laptops1.Get_ID()) {
if (List1.Check() == laptops1.Get_ID() || List1.Check() == 0) {
List1.AddList_Laptops1();
System.out.println("Succeed");
} else if (List2.Check() == laptops1.Get_ID() || List2.Check() == 0) {
List2.AddList_Laptops1();
System.out.println("Succeed");
} else {
List3.AddList_Laptops1();
System.out.println("Succeed");
}
} else if (temp8 == laptops2.Get_ID()) {
if (List1.Check() == laptops2.Get_ID() || List1.Check() == 0) {
List1.AddList_Laptops2();
System.out.println("Succeed");
} else if (List2.Check() == laptops2.Get_ID() || List2.Check() == 0) {
List2.AddList_Laptops2();
System.out.println("Succeed");
} else {
List3.AddList_Laptops2();
System.out.println("Succeed");
}
} else {
System.out.println();
System.out.println("ID not found");
}
}
if (Digit == 4) {
List1.DeleteList();
List2.DeleteList();
List3.DeleteList();
System.out.println("Your shopping list has been empted");
List1.GetList();
}
if (Digit == 5) {
double money, money1, money2, money3;
if (List1.Check() == 3) {
money1 = 0.8 * List1.CheckList();
} else {
money1 = List1.CheckList();
}
if (List2.Check() == 3) {
money2 = 0.8 * List2.CheckList();
} else {
money2 = List2.CheckList();
}
if (List3.Check() == 3) {
money3 = 0.8 * List3.CheckList();
} else {
money3 = List3.CheckList();
}
money = money1 + money2 + money3;
System.out.println();
System.out.println("You should paid");
System.out.println(money);
System.out.println("------------------------------");
}
}
}
}
要求:使用类的调用
**报告已丢失**
具体类之间的关系可通过代码开头的import语句推断出来
要求:使用数据库或者调用API或者添加界面完善期中作业的小系统,或者可以另外新建一个系统
package Map;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
public class ALiAround {
public String location;
public String keywords;
public String name;
public String type;
public String address;
public String pname;
public String cityname;
public String adname;
public void Do_around() throws IOException {
StringBuilder json = new StringBuilder();
URL name = new URL("https://restapi.amap.com/v3/place/around?key=b3524cc502a4fc39c0d2a2e5cb97b516&location"
+ "=" + this.location + "&keywords=" + this.keywords + "&types=&radius" + "=&offset=&page"
+ "=&extensions=all");
// URL name = new URL("https://restapi.amap.com/v3/direction/transit/integrated" +
// "?key=b3524cc502a4fc39c0d2a2e5cb97b516&origin=116.481028,39" +
// ".989643&destination=116.434446,39" +
// ".90816&city=北京&cityd=北京&strategy=0&nightflag=0");
URLConnection connection = name.openConnection();
connection.setDoOutput(true);
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String str;
while ((str = in.readLine()) != null) {
json.append(str);
}
in.close();
JSONObject jsonObject = JSONObject.parseObject(String.valueOf(json));
JSONArray pois = jsonObject.getJSONArray("pois");
JSONObject temp0 = pois.getJSONObject(Integer.parseInt("0"));
this.name = temp0.get("name").toString();
this.type = temp0.get("type").toString();
this.address = temp0.get("address").toString();
this.pname = temp0.get("pname").toString();
this.cityname = temp0.get("cityname").toString();
this.adname = temp0.get("adname").toString();
}
}
package Map;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
public class ALiBicycling {
public String origin;
public String destination;
public String distance;
public String duration;
public void Do_bicycling() throws IOException {
StringBuilder json = new StringBuilder();
URL name = new URL("https://restapi.amap" +
".com/v4/direction/bicycling?origin="+this.origin+
"&destination="
+this.destination+"&key=b3524cc502a4fc39c0d2a2e5cb97b516");
// URL name = new URL("https://restapi.amap
// .com/v3/direction/transit/integrated" +
// "?key=b3524cc502a4fc39c0d2a2e5cb97b516&origin=116.481028,39" +
// ".989643&destination=116.434446,39" +
// ".90816&city=北京&cityd=北京&strategy=0&nightflag=0");
URLConnection connection = name.openConnection();
connection.setDoOutput(true);
BufferedReader in =
new BufferedReader(new InputStreamReader(connection.getInputStream()));
String str;
while ((str = in.readLine()) != null) {
json.append(str);
}
in.close();
JSONObject jsonObject = JSONObject.parseObject(String.valueOf(json));
JSONObject data = (JSONObject) jsonObject.get("data");
JSONArray paths = data.getJSONArray("paths");
JSONObject temp0 = paths.getJSONObject(Integer.parseInt("0"));
this.distance = temp0.get("distance").toString();
this.duration = temp0.get("duration").toString();
}
}
package Map;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
public class ALiDriving {
public String origin;
public String destination;
public String distance;
public String duration;
public String strategy;
public String tolls;
public String traffic_lights;
public void Do_driving() throws IOException {
StringBuilder json = new StringBuilder();
URL name = new URL("https://restapi.amap" +
".com/v3/direction/driving?key" +
"=b3524cc502a4fc39c0d2a2e5cb97b516&origin=" + this.origin +
"&destination=" + this.destination + "&originid" +
"=&destinationid" +
"=&extensions" +
"=base&strategy=0" +
"&waypoints=&avoidpolygons=&avoidroad=");
// URL name = new URL("https://restapi.amap
// .com/v3/direction/transit/integrated" +
// "?key=b3524cc502a4fc39c0d2a2e5cb97b516&origin=116.481028,39" +
// ".989643&destination=116.434446,39" +
// ".90816&city=北京&cityd=北京&strategy=0&nightflag=0");
URLConnection connection = name.openConnection();
connection.setDoOutput(true);
BufferedReader in =
new BufferedReader(new InputStreamReader(connection.getInputStream()));
String str;
while ((str = in.readLine()) != null) {
json.append(str);
}
in.close();
JSONObject jsonObject = JSONObject.parseObject(String.valueOf(json));
JSONObject route = (JSONObject) jsonObject.get("route");
JSONArray paths = route.getJSONArray("paths");
JSONObject temp0 = paths.getJSONObject(Integer.parseInt("0"));
this.distance = temp0.get("distance").toString();
this.duration = temp0.get("duration").toString();
this.strategy = temp0.get("strategy").toString();
this.tolls = temp0.get("tolls").toString();
this.traffic_lights = temp0.get("traffic_lights").toString();
}
}
package Map;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.util.Scanner;
public class ALiGeocode {
public int return0;
public String address;
public String formatted_address;
public String adcode;
public String citycode;
public String location;
public void Do_geocode() throws IOException {
StringBuilder json = new StringBuilder();
Scanner scanner = new Scanner(System.in);
this.address = scanner.nextLine();
if (this.address.equals("0")) {
this.return0 = 1;
return;
}
System.out.print("处理中\n");
URL name = new URL("https://restapi.amap" + ".com/v3/geocode/geo?key=b3524cc502a4fc39c0d2a2e5cb97b516"
+ "&address=" + this.address + "&city=");
URLConnection connection = name.openConnection();
connection.setDoOutput(true);
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String str;
while ((str = in.readLine()) != null) {
json.append(str);
}
in.close();
JSONObject jsonObject = JSONObject.parseObject(String.valueOf(json));
JSONArray geocodes = jsonObject.getJSONArray("geocodes");
// System.out.println(geocodes); //用于测试是否接成功转换geocodes
JSONObject temp0 = (JSONObject) geocodes.get(Integer.parseInt("0"));
this.formatted_address = temp0.get("formatted_address").toString();
this.adcode = temp0.get("adcode").toString();
this.citycode = temp0.get("citycode").toString();
this.location = temp0.get("location").toString();
}
}
package Map;
import java.net.URL;
import java.io.*;
import java.net.URLConnection;
import com.alibaba.fastjson.JSONObject;
public class ALiIP {
public String ip;
public String province;
public String city;
public void Do_ip() throws IOException {
StringBuilder json = new StringBuilder();
URL name = new URL("https://restapi.amap.com/v3/ip?ip=" + this.ip +
"&output=json&key=b3524cc502a4fc39c0d2a2e5cb97b516");
// URL name = new URL("https://restapi.amap.com/v3/ip?ip=114.247.50" +
// ".2&output=json&key=b3524cc502a4fc39c0d2a2e5cb97b516");
URLConnection connection = name.openConnection();
connection.setDoOutput(true);
BufferedReader in =
new BufferedReader(new InputStreamReader(connection.getInputStream()));
String str;
while ((str = in.readLine()) != null) {
json.append(str);
}
in.close();
JSONObject jsonObject = JSONObject.parseObject(String.valueOf(json));
this.province=jsonObject.getString("province");
this.city=jsonObject.getString("city");
}
}
package Map;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
public class ALiIntegrated {
public String city;
public String cityd;
public String origin;
public String destination;
public String distance;
public String taxi_cost;
public String cost;
public String duration;
public void Do_integrated() throws IOException {
StringBuilder json = new StringBuilder();
URL name = new URL("https://restapi.amap.com/v3/direction/transit/integrated" +
"?key=b3524cc502a4fc39c0d2a2e5cb97b516&origin=" + this.origin +
"&destination" +
"=" + this.destination + "&city=" + this.city + "&cityd=" + this.cityd + "&strategy=0" +
"&nightflag=0");
// URL name = new URL("https://restapi.amap.com/v3/direction/transit/integrated" +
// "?key=b3524cc502a4fc39c0d2a2e5cb97b516&origin=116.481028,39" +
// ".989643&destination=116.434446,39" +
// ".90816&city=北京&cityd=北京&strategy=0&nightflag=0");
URLConnection connection = name.openConnection();
connection.setDoOutput(true);
BufferedReader in =
new BufferedReader(new InputStreamReader(connection.getInputStream()));
String str;
while ((str = in.readLine()) != null) {
json.append(str);
}
in.close();
JSONObject jsonObject = JSONObject.parseObject(String.valueOf(json));
JSONObject route = (JSONObject) jsonObject.get("route");
this.distance = route.get("distance").toString();
this.taxi_cost = route.get("taxi_cost").toString();
JSONArray transits=route.getJSONArray("transits");
JSONObject temp0=transits.getJSONObject(Integer.parseInt("0"));
this.cost=temp0.get("cost").toString();
this.duration = temp0.get("duration").toString();
}
}
//高德地图
package Map;
import java.io.IOException;
import java.util.Scanner;
public class ALiMap {
public void Geocode() throws IOException {
try {
ALiGeocode geocode0 = new ALiGeocode();
System.out.println("请输入地址(输入0可返回上一级菜单)");
geocode0.Do_geocode();
if (geocode0.return0==1){
System.out.println("\n返回上一级菜单\n");
return;
}
System.out.println("\n地址的结构化地址信息为:" + geocode0.formatted_address);
System.out.println("地址的区域编码为:" + geocode0.adcode);
System.out.println("地址的坐标点为:" + geocode0.location + "\n");
} catch (Exception e) {
System.out.println("\n输入有误\n");
}
}
public void Direction() throws IOException {
try {
ALiGeocode geocode1 = new ALiGeocode();
ALiGeocode geocode2 = new ALiGeocode();
ALiIntegrated integrated0 = new ALiIntegrated();
ALiDriving driving0 = new ALiDriving();
ALiBicycling bicycling0 = new ALiBicycling();
System.out.println("请输入出发点(输入0可返回上一级主菜单)");
geocode1.Do_geocode();
if (geocode1.return0==1){
System.out.println("\n返回上一级菜单\n");
return;
}
integrated0.origin = geocode1.location;
integrated0.city = geocode1.address;
driving0.origin = geocode1.location;
bicycling0.origin = geocode1.location;
System.out.println("请输入目的地(输入0可返回上一级菜单)");
geocode2.Do_geocode();
if (geocode2.return0==1){
System.out.println("\n返回上一级菜单\n");
return;
}
integrated0.destination = geocode2.location;
integrated0.cityd = geocode2.address;
driving0.destination = geocode2.location;
bicycling0.destination = geocode2.location;
integrated0.Do_integrated();
driving0.Do_driving();
bicycling0.Do_bicycling();
System.out.println("\n起点和终点的步行距离:" + integrated0.distance + "米");
System.out.println("出租车费用:" + integrated0.taxi_cost + "元");
System.out.println("最快捷公交换乘方案价格:" + integrated0.cost + "元");
System.out.println("最快捷公交换乘方案预计时间:" + integrated0.duration + "秒");
System.out.println("行驶距离:" + driving0.distance + "米");
System.out.println("预计行驶时间:" + driving0.duration + "秒");
System.out.println("导航策略:" + driving0.strategy);
System.out.println("此导航方案道路收费:" + driving0.tolls + "元");
System.out.println("此导航方案红绿灯个数:" + driving0.traffic_lights + "个");
System.out.println("起终点的骑行距离:" + bicycling0.distance + "米");
System.out.println("起终点的骑行时间:" + bicycling0.duration + "秒\n");
} catch (Exception e) {
System.out.println("\n输入有误\n");
}
}
public void Text() throws IOException {
try {
ALiText text0 = new ALiText();
Scanner scanner = new Scanner(System.in);
System.out.print("请输入查询关键词(如:美食、学校)(输入0可返回上一级菜单)\n");
text0.keywords = scanner.nextLine();
if (text0.keywords.equals("0")){
System.out.println("\n返回上一级菜单\n");
return;
}
System.out.print("处理中");
// System.out.print("请输入查询类型");
// this.types=scanner.nextLine();
System.out.print("请输入查询城市(仅限城市名,如:东莞、广州)(输入0可返回上一级菜单)\n");
text0.city = scanner.nextLine();
if (text0.city.equals("0")){
System.out.println("\n返回上一级菜单\n");
return;
}
System.out.print("处理中");
text0.Do_text();
System.out.println("\n\n名称:" + text0.name);
System.out.println("类型:" + text0.type);
System.out.println("地址:" + text0.pname + text0.cityname + text0.adname + text0.address + "\n");
} catch (Exception e) {
System.out.println("\n输入有误\n");
}
}
public void Around() throws IOException {
try {
ALiAround around0 = new ALiAround();
ALiGeocode geocode0 = new ALiGeocode();
System.out.println("请输入地点(输入0可返回上一级菜单)");
if (geocode0.return0==1){
System.out.println("\n返回上一级菜单\n");
return;
}
geocode0.Do_geocode();
around0.location = geocode0.location;
Scanner scanner = new Scanner(System.in);
System.out.print("请输入查询关键词(如:美食、学校)(输入0可返回上一级菜单)\n");
around0.keywords = scanner.nextLine();
if (around0.keywords.equals("0")){
System.out.println("\n返回上一级菜单\n");
return;
}
System.out.print("处理中");
around0.Do_around();
System.out.println("\n\n名称:" + around0.name);
System.out.println("类型:" + around0.type);
System.out.println("地址:" + around0.pname + around0.cityname + around0.adname + around0.address + "\n");
} catch (Exception e) {
System.out.println("\n输入有误\n");
}
}
public void Ip() throws IOException {
try {
ALiIP ip0 = new ALiIP();
System.out.println("请输入需要搜索的IP地址(仅支持国内)(输入0可返回上一级菜单)");
Scanner scanner = new Scanner(System.in);
ip0.ip = scanner.nextLine();
if (ip0.ip.equals("0")){
System.out.println("\n返回上一级菜单\n");
return;
}
System.out.print("处理中");
ip0.Do_ip();
System.out.println("\n\nIP地址:" + ip0.province + ip0.city + "\n");
} catch (Exception e) {
System.out.println("\n输入有误\n");
}
}
public void WeatherInfo() throws IOException {
try {
ALiGeocode geocode0 = new ALiGeocode();
ALiWeatherInfo weatherInfo0 = new ALiWeatherInfo();
System.out.println("请输入地点(输入0可返回上一级菜单)");
geocode0.Do_geocode();
if (geocode0.return0==1){
System.out.println("\n返回上一级菜单\n");
return;
}
weatherInfo0.city = geocode0.adcode;
weatherInfo0.Do_weatherInfo();
System.out.println("\n" + geocode0.formatted_address + "今日的天气:");
System.out.println("日期:\t\t\t\t\t" + weatherInfo0.date00);
System.out.println("星期:\t\t\t\t\t" + weatherInfo0.week00);
System.out.println("白天天气现象:\t\t\t" + weatherInfo0.dayweather00);
System.out.println("晚上天气现象:\t\t\t" + weatherInfo0.nightweather00);
System.out.println("白天温度(摄氏度):\t\t" + weatherInfo0.daytemp00);
System.out.println("晚上温度(摄氏度):\t\t" + weatherInfo0.nighttemp00);
System.out.println("白天风向:\t\t\t\t" + weatherInfo0.daywind00);
System.out.println("晚上风向:\t\t\t\t" + weatherInfo0.nightwind00);
System.out.println("白天风力(级):\t\t\t" + weatherInfo0.daypower00);
System.out.println("晚上风力(级):\t\t\t" + weatherInfo0.nightpower00);
System.out.println("\n" + geocode0.formatted_address + "未来三日的天气:");
System.out.println("\n" + geocode0.formatted_address + "明日的天气:");
System.out.println("日期:\t\t\t\t\t" + weatherInfo0.date01);
System.out.println("星期:\t\t\t\t\t" + weatherInfo0.week01);
System.out.println("白天天气现象:\t\t\t" + weatherInfo0.dayweather01);
System.out.println("晚上天气现象:\t\t\t" + weatherInfo0.nightweather01);
System.out.println("白天温度(摄氏度):\t\t" + weatherInfo0.daytemp01);
System.out.println("晚上温度(摄氏度):\t\t" + weatherInfo0.nighttemp01);
System.out.println("白天风向:\t\t\t\t" + weatherInfo0.daywind01);
System.out.println("晚上风向:\t\t\t\t" + weatherInfo0.nightwind01);
System.out.println("白天风力(级):\t\t\t" + weatherInfo0.daypower01);
System.out.println("晚上风力(级):\t\t\t" + weatherInfo0.nightpower01);
System.out.println("\n" + geocode0.formatted_address + "后天的天气:");
System.out.println("日期:\t\t\t\t\t" + weatherInfo0.date02);
System.out.println("星期:\t\t\t\t\t" + weatherInfo0.week02);
System.out.println("白天天气现象:\t\t\t" + weatherInfo0.dayweather02);
System.out.println("晚上天气现象:\t\t\t" + weatherInfo0.nightweather02);
System.out.println("白天温度(摄氏度):\t\t" + weatherInfo0.daytemp02);
System.out.println("晚上温度(摄氏度):\t\t" + weatherInfo0.nighttemp02);
System.out.println("白天风向:\t\t\t\t" + weatherInfo0.daywind02);
System.out.println("晚上风向:\t\t\t\t" + weatherInfo0.nightwind02);
System.out.println("白天风力(级):\t\t\t" + weatherInfo0.daypower02);
System.out.println("晚上风力(级):\t\t\t" + weatherInfo0.nightpower02);
System.out.println("\n" + geocode0.formatted_address + "大后天的天气:");
System.out.println("日期:\t\t\t\t\t" + weatherInfo0.date03);
System.out.println("星期:\t\t\t\t\t" + weatherInfo0.week03);
System.out.println("白天天气现象:\t\t\t" + weatherInfo0.dayweather03);
System.out.println("晚上天气现象:\t\t\t" + weatherInfo0.nightweather03);
System.out.println("白天温度(摄氏度):\t\t" + weatherInfo0.daytemp03);
System.out.println("晚上温度(摄氏度):\t\t" + weatherInfo0.nighttemp03);
System.out.println("白天风向:\t\t\t\t" + weatherInfo0.daywind03);
System.out.println("晚上风向:\t\t\t\t" + weatherInfo0.nightwind03);
System.out.println("白天风力(级):\t\t\t" + weatherInfo0.daypower03);
System.out.println("晚上风力(级):\t\t\t" + weatherInfo0.nightpower03 + "\n");
} catch (Exception e) {
System.out.println("\n输入有误\n");
}
}
public static void Alimap() throws IOException {
// write your code here
ALiMap function = new ALiMap();
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.print("选择功能\n");
System.out.print("输入1——地理编码\n");
System.out.print("输入2——路径规划\n");
System.out.print("输入3——关键字搜索\n");
System.out.print("输入4——周边搜索\n");
System.out.print("输入5——IP定位\n");
System.out.print("输入6——天气查询\n");
System.out.print("输入0——返回主菜单\n");
String Digit = scanner.nextLine();
switch (Digit) {
case "1":
function.Geocode();
continue;
case "2":
function.Direction();
continue;
case "3":
function.Text();
continue;
case "4":
function.Around();
continue;
case "5":
function.Ip();
continue;
case "6":
function.WeatherInfo();
continue;
case "0":
System.out.println("\n返回主菜单\n");
return;
default:
System.out.println("输入有误\n");
}
}
}
}
package Map;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
public class ALiText {
public String keywords;
public String types;
public String city;
public String name;
public String type;
public String address;
public String pname;
public String cityname;
public String adname;
public void Do_text() throws IOException {
StringBuilder json = new StringBuilder();
URL name = new URL("https://restapi.amap" +
".com/v3/place/text?key=b3524cc502a4fc39c0d2a2e5cb97b516&keywords" +
"=" + this.keywords + "&types=&city=" + this.city +
"&children" +
"=&offset=&page=&extensions=base");
// URL name = new URL("https://restapi.amap.com/v3/direction/transit/integrated" +
// "?key=b3524cc502a4fc39c0d2a2e5cb97b516&origin=116.481028,39" +
// ".989643&destination=116.434446,39" +
// ".90816&city=北京&cityd=北京&strategy=0&nightflag=0");
URLConnection connection = name.openConnection();
connection.setDoOutput(true);
BufferedReader in =
new BufferedReader(new InputStreamReader(connection.getInputStream()));
String str;
while ((str = in.readLine()) != null) {
json.append(str);
}
in.close();
JSONObject jsonObject = JSONObject.parseObject(String.valueOf(json));
JSONArray pois = jsonObject.getJSONArray("pois");
JSONObject temp0 = pois.getJSONObject(Integer.parseInt("0"));
this.name = temp0.get("name").toString();
this.type = temp0.get("type").toString();
this.address=temp0.get("address").toString();
this.pname=temp0.get("pname").toString();
this.cityname=temp0.get("cityname").toString();
this.adname=temp0.get("adname").toString();
}
}
package Map;
import java.net.URL;
import java.io.*;
import java.net.URLConnection;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
public class ALiWeatherInfo {
public String city;
public String date00;
public String dayweather00;
public String daywind00;
public String week00;
public String daypower00;
public String daytemp00;
public String nightwind00;
public String nighttemp00;
public String nightweather00;
public String nightpower00;
public String date01;
public String dayweather01;
public String daywind01;
public String week01;
public String daypower01;
public String daytemp01;
public String nightwind01;
public String nighttemp01;
public String nightweather01;
public String nightpower01;
public String date02;
public String dayweather02;
public String daywind02;
public String week02;
public String daypower02;
public String daytemp02;
public String nightwind02;
public String nighttemp02;
public String nightweather02;
public String nightpower02;
public String date03;
public String dayweather03;
public String daywind03;
public String week03;
public String daypower03;
public String daytemp03;
public String nightwind03;
public String nighttemp03;
public String nightweather03;
public String nightpower03;
public void Do_weatherInfo() throws IOException {
StringBuilder json = new StringBuilder();
URL name = new URL("https://restapi.amap" + ".com/v3/weather/weatherInfo?city=" + this.city
+ "&extensions=all&key=b3524cc502a4fc39c0d2a2e5cb97b516");
// URL name = new URL("https://restapi.amap.com/v3/ip?ip=114.247.50" +
// ".2&output=json&key=b3524cc502a4fc39c0d2a2e5cb97b516");
URLConnection connection = name.openConnection();
connection.setDoOutput(true);
BufferedReader in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
String str;
while ((str = in.readLine()) != null) {
// System.out.print(str);
json.append(str);
}
in.close();
JSONObject jsonObject = JSONObject.parseObject(String.valueOf(json));
JSONArray forecasts = jsonObject.getJSONArray("forecasts");
JSONObject temp0 = forecasts.getJSONObject(Integer.parseInt("0"));
JSONArray casts = temp0.getJSONArray("casts");
JSONObject temp00 = casts.getJSONObject(Integer.parseInt("0"));
JSONObject temp01 = casts.getJSONObject(Integer.parseInt("1"));
JSONObject temp02 = casts.getJSONObject(Integer.parseInt("2"));
JSONObject temp03 = casts.getJSONObject(Integer.parseInt("3"));
this.date00 = temp00.get("date").toString();
this.dayweather00 = temp00.get("dayweather").toString();
this.daywind00 = temp00.get("daywind").toString();
this.week00 = temp00.get("week").toString();
this.daypower00 = temp00.get("daypower").toString();
this.daytemp00 = temp00.get("daytemp").toString();
this.nightwind00 = temp00.get("nightwind").toString();
this.nighttemp00 = temp00.get("nighttemp").toString();
this.nightweather00 = temp00.get("nightweather").toString();
this.nightpower00 = temp00.get("nightpower").toString();
this.date01 = temp01.get("date").toString();
this.dayweather01 = temp01.get("dayweather").toString();
this.daywind01 = temp01.get("daywind").toString();
this.week01 = temp01.get("week").toString();
this.daypower01 = temp01.get("daypower").toString();
this.daytemp01 = temp01.get("daytemp").toString();
this.nightwind01 = temp01.get("nightwind").toString();
this.nighttemp01 = temp01.get("nighttemp").toString();
this.nightweather01 = temp01.get("nightweather").toString();
this.nightpower01 = temp01.get("nightpower").toString();
this.date02 = temp02.get("date").toString();
this.dayweather02 = temp02.get("dayweather").toString();
this.daywind02 = temp02.get("daywind").toString();
this.week02 = temp02.get("week").toString();
this.daypower02 = temp02.get("daypower").toString();
this.daytemp02 = temp02.get("daytemp").toString();
this.nightwind02 = temp02.get("nightwind").toString();
this.nighttemp02 = temp02.get("nighttemp").toString();
this.nightweather02 = temp02.get("nightweather").toString();
this.nightpower02 = temp02.get("nightpower").toString();
this.date03 = temp03.get("date").toString();
this.dayweather03 = temp03.get("dayweather").toString();
this.daywind03 = temp03.get("daywind").toString();
this.week03 = temp03.get("week").toString();
this.daypower03 = temp03.get("daypower").toString();
this.daytemp03 = temp03.get("daytemp").toString();
this.nightwind03 = temp03.get("nightwind").toString();
this.nighttemp03 = temp03.get("nighttemp").toString();
this.nightweather03 = temp03.get("nightweather").toString();
this.nightpower03 = temp03.get("nightpower").toString();
}
}
//百度地图IP定位功能
package Map;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import com.alibaba.fastjson.JSONObject;
public class BDIP {
public String ip;
public String address = null;
public String city_code = null;
public String message = "0";
public void ip_location() throws IOException {
StringBuilder json = new StringBuilder();
URL URL = new URL("https://api.map.baidu.com/location/ip?ip=" + ip
+ "&ak=75EYHRd9dg4ful7Qxwn1wWsMQjA3I0Ep&coor=bd09ll");
/*URL URL = new URL("https://api.map.baidu.com/location/ip?ip=183.63.102.207"
+ "&ak=75EYHRd9dg4ful7Qxwn1wWsMQjA3I0Ep&coor=bd09ll"); //测试URL*/
URLConnection connection = URL.openConnection();
connection.setDoOutput(true);
BufferedReader in = new BufferedReader(new InputStreamReader(URL.openStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
json.append(inputLine);
in.close();
JSONObject jsonObject = JSONObject.parseObject(String.valueOf(json));
if (jsonObject.get("status").toString().equals("0")) {
JSONObject content = jsonObject.getJSONObject("content");
JSONObject address_detail = content.getJSONObject("address_detail");
String province = address_detail.get("province").toString();
String city = address_detail.get("city").toString();
String district = address_detail.get("district").toString();
String street = address_detail.get("street").toString();
String street_number = address_detail.get("street_number").toString();
this.address = province + city + district + street + street_number;
this.city_code = address_detail.get("city_code").toString();
}
else {
message = jsonObject.get("message").toString();
System.out.println("\n错误信息:" + message + "\n");
}
}
}
\ No newline at end of file
//百度地图
package Map;
import java.io.IOException;
import java.util.Scanner;
public class BDMap {
public void BDgeocode() throws IOException {
try {
BDgeocode geocode0 = new BDgeocode();
System.out.print("请输入需要查询的地点(输入 0 可返回上一级菜单):");
geocode0.geocode();
if(geocode0.return0 == 1) {
System.out.println("\n返回上一级菜单\n");
return;
}
System.out.println("\n该地的坐标点为:" + geocode0.location + "\n");
} catch (Exception e) {
System.out.println("\n输入有误\n");
}
}
public void BDPathPlanning() throws IOException {
try {
BDPathPlanning pathplanning = new BDPathPlanning();
BDgeocode geocode1 = new BDgeocode();
BDgeocode geocode2 = new BDgeocode();
System.out.print("请输入出发地(输入 0 可返回上一级菜单):");
geocode1.geocode();
if(geocode1.return0 == 1) {
System.out.println("\n返回上一级菜单\n");
return;
}
System.out.print("请输入目的地:");
geocode2.geocode();
System.out.println("处理中...");
pathplanning.origin = geocode1.formatchange_location;
pathplanning.destination = geocode2.formatchange_location;
/*----------------------riding----------------------*/
pathplanning.riding();
if(pathplanning.taxi_time_h != 0) {
System.out.println("\n起点和终点的骑行距离为:" + pathplanning.riding_distance + "米,预计耗时"
+ pathplanning.riding_time_h + "小时" + pathplanning.riding_time_min + "分钟"
+ pathplanning.riding_time_s + "秒");
}
else if(pathplanning.riding_time_min != 0) {
System.out.println("\n起点和终点的骑行距离为:" + pathplanning.riding_distance + "米,预计耗时"
+ pathplanning.riding_time_min + "分钟" + pathplanning.riding_time_s + "秒");
}
else System.out.println("\n起点和终点的骑行距离为:"+ pathplanning.riding_distance + "米,预计耗时"
+ pathplanning.riding_time_s + "秒");
/*-----------------------walk-----------------------*/
pathplanning.walking();
if(pathplanning.walk_time_h != 0) {
System.out.println("起点和终点的步行距离为:" + pathplanning.walk_distance + "米,预计耗时"
+ pathplanning.walk_time_h + "小时" + pathplanning.walk_time_min + "分钟"
+ pathplanning.walk_time_s + "秒");
}
else if(pathplanning.walk_time_min != 0) {
System.out.println("起点和终点的步行距离为:"+ pathplanning.walk_distance + "米,预计耗时"
+ pathplanning.walk_time_min + "分钟" + pathplanning.walk_time_s + "秒");
}
else System.out.println("起点和终点的步行距离为:"+ pathplanning.walk_distance + "米,预计耗时"
+ pathplanning.walk_time_s + "秒");
/*-----------------------taxi-----------------------*/
pathplanning.transit();
if(pathplanning.taxi_time_h != 0) {
System.out.println("出租车行驶距离为:" + pathplanning.taxi_distance + "米,预计耗时"
+ pathplanning.taxi_time_h + "小时" + pathplanning.taxi_time_min + "分钟"
+ pathplanning.taxi_time_s + "秒,预计费用为:" + pathplanning.taxi_cost + "元");
}
else if(pathplanning.taxi_time_min != 0) {
System.out.println("出租车行驶距离为:" + pathplanning.taxi_distance + "米,预计耗时"
+ pathplanning.taxi_time_min + "分钟" + pathplanning.taxi_time_s
+ "秒,预计费用为:" + pathplanning.taxi_cost + "元");
}
else System.out.println("出租车行驶距离为:" + pathplanning.taxi_distance + "米,预计耗时"
+ pathplanning.taxi_time_s + "秒,预计费用为:" + pathplanning.taxi_cost + "元");
/*-----------------------bus------------------------*/
if(pathplanning.bus_time_h != 0) {
System.out.println("最快捷公交换乘方案价格为:" + pathplanning.bus_cost + "元,预计时间为"
+ pathplanning.bus_time_h + "小时" + pathplanning.bus_time_min + "分钟"
+ pathplanning.bus_time_s + "秒\n");
}
else if(pathplanning.bus_time_min != 0) {
System.out.println("最快捷公交换乘方案价格为:" + pathplanning.bus_cost + "元,预计时间为"
+ pathplanning.bus_time_min + "分钟"+ pathplanning.bus_time_s + "秒\n");
}
else System.out.println("最快捷公交换乘方案价格为:" + pathplanning.bus_cost + "元,预计时间为"
+ pathplanning.bus_time_s + "秒\n");
} catch (Exception e) {
System.out.println("\n输入有误\n");
}
}
public void BDSearch() throws IOException {
try {
BDSearch search = new BDSearch();
Scanner scanner = new Scanner(System.in);
System.out.print("请输入需要检索的关键字(如:美食、银行、XX大厦等。输入 0 可返回上一级菜单):");
search.query = scanner.nextLine();
if(search.query.equals("0")) {
System.out.println("\n返回上一级菜单\n");
return;
}
System.out.print("请输入需要检索城市(仅限城市名,如:东莞、广州等):");
search.region = scanner.nextLine();
System.out.println("处理中...");
search.search();
if(search.message.equals("ok")) {
System.out.println("\n检索结果 1 :");
System.out.println("地点名:" + search.name0);
System.out.println("地址:" + search.address0);
System.out.println(search.location0 + "\n");
if(search.name1.equals(null)) {
System.out.println("检索结果 2 :");
System.out.println("地点名:" + search.name1);
System.out.println("地址:" + search.address1);
System.out.println(search.location1 + "\n");
}
}
} catch (Exception e) {
System.out.println("\n输入有误\n");
}
}
public void BDip() throws IOException {
BDIP ip_location = new BDIP();
try {
Scanner scanner = new Scanner(System.in);
System.out.print("请输入需要查询的IP地址(如果输入为空,默认查询本机;输入 0 可返回上一级菜单):");
ip_location.ip = scanner.nextLine();
if(ip_location.ip.equals("0")) {
System.out.println("\n返回上一级菜单\n");
return;
}
System.out.println("处理中...");
ip_location.ip_location();
if(ip_location.message.equals("0")) {
System.out.println("\n此IP地址的地址信息为:" + ip_location.address);
System.out.println("所在城市的百度城市代码为:" + ip_location.city_code + "\n");
}
}catch (Exception e) {
System.out.println("\n输入有误\n");
}
}
public static void BDmap() throws IOException{
BDMap BDfunction = new BDMap();
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("请输入对应数字选择功能:");
System.out.println("1——地理编码");
System.out.println("2——路径规划");
System.out.println("3——地点检索");
System.out.println("4——IP定位");
System.out.println("0——返回主菜单");
int Digit = scanner.nextInt();
switch(Digit) {
case 1:
BDfunction.BDgeocode();
continue;
case 2:
BDfunction.BDPathPlanning();
continue;
case 3:
BDfunction.BDSearch();
continue;
case 4:
BDfunction.BDip();
continue;
case 0:
System.out.println("\n返回主菜单\n");
return;
default:
System.out.println("\n输入有误\n");
}
}
}
}
\ No newline at end of file
//百度地图路径规划功能
package Map;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.JSONArray;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
public class BDPathPlanning {
public String origin;
public String destination;
public String riding_distance;
public int riding_time_h;
public int riding_time_min;
public int riding_time_s;
public String walk_distance;
public int walk_time_h;
public int walk_time_min;
public int walk_time_s;
public String taxi_distance;
public int taxi_time_h;
public int taxi_time_min;
public int taxi_time_s;
public String taxi_cost;
public String bus_cost;
public int bus_time_h;
public int bus_time_min;
public int bus_time_s;
public void riding() throws IOException {
StringBuilder json1 = new StringBuilder();
URL URL1 = new URL("http://api.map.baidu.com/directionlite/v1/riding?origin=" +
origin + "&destination=" + destination + "&ak=75EYHRd9dg4ful7Qxwn1wWsMQjA3I0Ep");
/*URL URL1 = new URL("http://api.map.baidu.com/directionlite/v1/riding?" +
"origin=40.01116,116.339303&destination=39.936404,116.452562" +
"&ak=75EYHRd9dg4ful7Qxwn1wWsMQjA3I0Ep"); //测试URL */
//此处坐标格式为“纬度(double),经度(double)”,(小数点后不超过6位)
URLConnection connection1 =URL1.openConnection();
connection1.setDoOutput(true);
BufferedReader in1 = new BufferedReader(new InputStreamReader(URL1.openStream()));
String inputLine1;
while ((inputLine1 = in1.readLine()) != null)
json1.append(inputLine1);
in1.close();
JSONObject r_jsonObject = JSONObject.parseObject(String.valueOf(json1));
JSONObject result1 = r_jsonObject.getJSONObject("result");
JSONArray Array_r_route = result1.getJSONArray("routes"); //获取数组
JSONObject r_route = Array_r_route.getJSONObject(0);
riding_distance = r_route.get("distance").toString();
String riding_duration = r_route.get("duration").toString();
//时间由“秒”换算为“时分秒”
int riding_duration_h = 0;
int riding_duration_min = 0;
int riding_duration_s = 0;
if(Integer.parseInt(riding_duration) > 59) {
riding_duration_min = Integer.parseInt(riding_duration) / 60;
riding_duration_s = Integer.parseInt(riding_duration) % 60;
if(riding_duration_min > 59) {
riding_duration_h = riding_duration_min / 60;
riding_duration_min = riding_duration_min % 60;
}
}
else riding_time_s = Integer.parseInt(riding_duration);
riding_time_h = riding_duration_h;
riding_time_min = riding_duration_min;
riding_time_s = riding_duration_s;
}
public void walking() throws IOException {
StringBuilder json2 = new StringBuilder();
URL URL2 = new URL("http://api.map.baidu.com/directionlite/v1/walking?origin=" +
origin + "&destination=" + destination + "&ak=75EYHRd9dg4ful7Qxwn1wWsMQjA3I0Ep");
/*URL URL2 = new URL("http://api.map.baidu.com/directionlite/v1/walking?" +
"origin=40.01116,116.339303&destination=39.936404,116.452562" +
"&ak=75EYHRd9dg4ful7Qxwn1wWsMQjA3I0Ep"); //测试URL */
//此处坐标格式为“纬度(double),经度(double)”,(小数点后不超过6位)
URLConnection connection2 =URL2.openConnection();
connection2.setDoOutput(true);
BufferedReader in2 = new BufferedReader(new InputStreamReader(URL2.openStream()));
String inputLine2;
while ((inputLine2 = in2.readLine()) != null)
json2.append(inputLine2);
in2.close();
JSONObject w_jsonObject = JSONObject.parseObject(String.valueOf(json2));
JSONObject result2 = w_jsonObject.getJSONObject("result");
JSONArray Array_w_route = result2.getJSONArray("routes"); //获取数组
JSONObject w_route = Array_w_route.getJSONObject(0);
walk_distance = w_route.get("distance").toString();
String walk_duration = w_route.get("duration").toString();
//时间由“秒”换算为“时分秒”
int walk_duration_h = 0;
int walk_duration_min = 0;
int walk_duration_s = 0;
if(Integer.parseInt(walk_duration) > 59) {
walk_duration_min = Integer.parseInt(walk_duration) / 60;
walk_duration_s = Integer.parseInt(walk_duration) % 60;
if(walk_duration_min > 59) {
walk_duration_h = walk_duration_min / 60;
walk_duration_min = walk_duration_min % 60;
}
}
else walk_time_s = Integer.parseInt(walk_duration);
walk_time_h = walk_duration_h;
walk_time_min = walk_duration_min;
walk_time_s = walk_duration_s;
}
public void transit() throws IOException {
StringBuilder json3 = new StringBuilder();
URL URL3 = new URL("http://api.map.baidu.com/directionlite/v1/transit?origin=" +
origin + "&destination=" + destination + "&ak=75EYHRd9dg4ful7Qxwn1wWsMQjA3I0Ep");
//URL URL3 = new URL("http://api.map.baidu.com/directionlite/v1/transit?origin=40.01116,116.339303&destination=39.936404,116.452562&ak=75EYHRd9dg4ful7Qxwn1wWsMQjA3I0Ep");//����URL
//此处坐标格式为“纬度(double),经度(double)”,(小数点后不超过6位)
URLConnection connection1 =URL3.openConnection();
connection1.setDoOutput(true);
BufferedReader in3 = new BufferedReader(new InputStreamReader(URL3.openStream()));
String inputLine3;
while ((inputLine3 = in3.readLine()) != null)
json3.append(inputLine3);
in3.close();
JSONObject t_jsonObject = JSONObject.parseObject(String.valueOf(json3));
JSONObject result3 = t_jsonObject.getJSONObject("result");
/*----------------taxi----------------*/
JSONObject taxi = result3.getJSONObject("taxi");
taxi_distance = taxi.getString("distance").toString();
String taxi_duration = taxi.getString("duration").toString();
int taxi_duration_h = 0;
int taxi_duration_min = 0;
int taxi_duration_s = 0;
if(Integer.parseInt(taxi_duration) > 59) {
taxi_duration_min = Integer.parseInt(taxi_duration) / 60;
taxi_duration_s = Integer.parseInt(taxi_duration) % 60;
if(taxi_duration_min > 59) {
taxi_duration_h = taxi_duration_min / 60;
taxi_duration_min = taxi_duration_min % 60;
}
}
else taxi_duration_s = Integer.parseInt(taxi_duration);
taxi_time_h = taxi_duration_h;
taxi_time_min = taxi_duration_min;
taxi_time_s = taxi_duration_s;
JSONArray taxi_detail = taxi.getJSONArray("detail"); //获取数组
JSONObject t_cost = taxi_detail.getJSONObject(0);
taxi_cost = t_cost.get("total_price").toString();
/*----------------bus----------------*/
JSONArray b_route = result3.getJSONArray("routes"); //获取数组
JSONObject best_bus_route = b_route.getJSONObject(0);
bus_cost = best_bus_route.getJSONArray("line_price").getJSONObject(0).get("line_price").toString();
String bus_duration = best_bus_route.get("duration").toString();
//时间由“秒”换算为“时分秒”
int bus_duration_h = 0;
int bus_duration_min = 0;
int bus_duration_s = 0;
if(Integer.parseInt(bus_duration) > 59) {
bus_duration_min = Integer.parseInt(bus_duration) / 60;
bus_duration_s = Integer.parseInt(bus_duration) % 60;
if(bus_duration_min > 59) {
bus_duration_h = bus_duration_min / 60;
bus_duration_min = bus_duration_min % 60;
}
}
else bus_duration_s = Integer.parseInt(bus_duration);
bus_time_h = bus_duration_h;
bus_time_min = bus_duration_min;
bus_time_s = bus_duration_s;
}
}
\ No newline at end of file
//百度地图地点检索功能
package Map;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
public class BDSearch {
public String query;
public String region;
public String name0 = null;
public String address0 = null;
public String location0 = null;
public String name1 = "0";
public String address1 = null;
public String location1 = null;
public String message = null;
public void search() throws IOException {
StringBuilder json = new StringBuilder();
URL URL = new URL("http://api.map.baidu.com/place/v2/search?query=" + query + "&region=" + region
+ "&page_size=2&output=json&ak=75EYHRd9dg4ful7Qxwn1wWsMQjA3I0Ep");
/*URL URL = new URL("http://api.map.baidu.com/place/v2/search?query=ATM机&tag=银行&region=广州"
+ "&output=json&ak=75EYHRd9dg4ful7Qxwn1wWsMQjA3I0Ep"); //测试URL*/
URLConnection connection = URL.openConnection();
connection.setDoOutput(true);
BufferedReader in = new BufferedReader(new InputStreamReader(URL.openStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
json.append(inputLine);
in.close();
JSONObject jsonObject = JSONObject.parseObject(String.valueOf(json));
if(jsonObject.get("status").toString().equals("0")) {
message = jsonObject.get("message").toString();
JSONArray result = jsonObject.getJSONArray("results");
JSONObject info0 = result.getJSONObject(0);
name0 = info0.get("name").toString();
address0 = info0.get("address").toString();
JSONObject locat0 = info0.getJSONObject("location");
location0 = "经度:" + locat0.get("lng").toString() + ",纬度:" + locat0.get("lat").toString();
JSONObject info1 = result.getJSONObject(1);
name1 = info1.get("name").toString();
address1 = info1.get("address").toString();
JSONObject locat1 = info1.getJSONObject("location");
location1 = "经度:" + locat1.get("lng").toString() + ",纬度:" + locat1.get("lat").toString();
}
else {
message = jsonObject.get("message").toString();
System.out.println("\n错误信息:" + message + "\n");
}
}
}
\ No newline at end of file
//百度地图地理编码功能
package Map;
import com.alibaba.fastjson.JSONObject;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;
import java.text.DecimalFormat;
import java.util.Scanner;
public class BDgeocode {
public int return0;
public String address;
public String location;
public String formatchange_location;
public void geocode() throws IOException {
StringBuilder json = new StringBuilder();
Scanner scanner = new Scanner(System.in);
address = scanner.nextLine();
if(address.equals("0")) {
return0 = 1;
return;
}
URL URL = new URL("http://api.map.baidu.com/geocoding/v3/?address=" + address + "&output=json&ak=75EYHRd9dg4ful7Qxwn1wWsMQjA3I0Ep");
URLConnection connection = URL.openConnection();
connection.setDoOutput(true);
BufferedReader in = new BufferedReader(new InputStreamReader(URL.openStream()));
String inputLine;
while ((inputLine = in.readLine()) != null)
json.append(inputLine);
in.close();
JSONObject jsonObject = JSONObject.parseObject(String.valueOf(json));
JSONObject result = jsonObject.getJSONObject("result");
JSONObject location = result.getJSONObject("location");
this.location = "经度:" + location.get("lng").toString() + ",纬度:" + location.get("lat").toString();
String lng = location.get("lng").toString();
String lat = location.get("lat").toString();
this.formatchange_location = FormatChange(lng,lat);
}
public String FormatChange(String a , String b) throws IOException { //接收坐标为:“经度,纬度”
DecimalFormat df = new DecimalFormat("0.000000");
float f1 = Float.parseFloat(a);
float f2 = Float.parseFloat(b);
String s1 = df.format(f1);
String s2 = df.format(f2);
String s = s2 + "," + s1; //此时转换后坐标为:“纬度,经度”
return s;
}
}
\ No newline at end of file
/************************************************************
*JAVA程序设计-大作业 *
*作品名称:地图系统 *
*作者:梁志浩(20172333075)、何尔恒(2017233****) *
*该地图系统可选择使用高德地图或百度地图 *
*为确保程序正常使用,请添加 lib 目录下 fastjson-1.2.62.jar *
************************************************************/
package Map;
import java.io.IOException;
import java.util.Scanner;
public class MapMain {
public static void welcome() {
}
public static void main(String[] args) throws IOException {
Scanner scanner = new Scanner(System.in);
while (true) {
System.out.println("****欢迎使用地图程序,请输入对应数字选择地图****");
System.out.println("1——高德地图");
System.out.println("2——百度地图");
System.out.println("0——退出程序");
int Digit = scanner.nextInt();
switch(Digit) {
case 1:
System.out.println("欢迎使用高德地图!");
ALiMap.Alimap();
continue;
case 2:
System.out.println("欢迎使用百度地图!");
BDMap.BDmap();
continue;
case 0:
System.out.println("程序结束");
System.exit(0);
scanner.close();//当此后非程序结束,须删除此行
continue;
default:
System.out.println("\n输入有误\n");
}
}
}
}
\ No newline at end of file
a=[1, 2*10^3, 2*10^9]; %微分方程左侧系数
b=[2*10^9]; %微分方程右侧系数
sys=tf(b, a); %建立系统描述
t=[0:0.00001:0.008]; %定义仿真时间
%e1=1.*dirac(t-0);
e1=(t==0).*1;
f1=lsim(sys, e1, t); %用e1激励sys, 输出为f1
e2=1.*heaviside(t);
f2=lsim(sys, e2, t); %用e2激励sys, 输出为f2
figure;
subplot(1, 2, 1);
hold on, box on;
%set(gca, 'YScale', 'log');
set(gca, 'FontSize', 16);
plot(t, e1, 'k-', t, e2, 'k-.');
legend('e_1', 'e_2');
xlabel('time/s');
ylabel('input');
subplot(1, 2, 2);
hold on, box on;
%set(gca, 'YScale', 'log');
set(gca, 'FontSize', 16);
plot(t, f1, 'k-', t, f2, 'k-.');
legend('f_1', 'f_2');
xlabel('time/s');
ylabel('output');
\ No newline at end of file
a=10^3;
w=2*10^9;
w0=w^0.5;
b=(w-(a^2))^0.5;
o=atan(b/a);
t=[0:0.001:0.008];
h=(w/b)*exp(-a.*t).*sin(b.*t);
g=1-((w0/b)*exp(-a.*t).*sin(b.*t+o));
subplot(1, 2, 1);
hold on, box on;
plot(t, h);
title('弤Ӧh(t)');
subplot(1, 2, 2);
hold on, box on;
plot(t, g);
title('ԾӦg(t)');
\ No newline at end of file
二阶电路系统的设计与测试分析
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册