# include <stdio.h>
# include <stdlib.h>
# include <time.h>
# include "euler.h"
/******************************************************************************/
void euler ( void dydt ( double x, double y[], double yp[] ), double tspan[2],
double y0[], int n, int m, double t[], double y[] )
/******************************************************************************/
/*
Purpose:
euler approximates the solution to an ODE using Euler's method.
Licensing:
This code is distributed under the GNU LGPL license.
Modified:
25 April 2020
Author:
John Burkardt
Input:
dydt: a function that evaluates the right hand side of the ODE.
double tspan[2]: contains the initial and final times.
double y0[m]: a column vector containing the initial condition.
int n: the number of steps to take.
int m: the number of variables.
Output:
double t[n+1], y[m*(n+1)]: the times and solution values.
*/
{
double dt;
double *dy;
int i;
int j;
double tfirst;
double tlast;
dy = ( double * ) malloc ( m * sizeof ( double ) );
tfirst = tspan[0];
tlast = tspan[1];
dt = ( tlast - tfirst ) / ( double ) ( n );
j = 0;
t[j] = tspan[0];
for ( i = 0; i < m; i++ )
{
y[i+j*m] = y0[i];
}
for ( j = 0; j < n; j++ )
{
dydt ( t[j], y+j*m, dy );
t[j+1] = t[j] + dt;
for ( i = 0; i < m; i++ )
{
y[i+(j+1)*m] = y[i+j*m] + dt * dy[i];
}
}
free ( dy );
return;
}
/******************************************************************************/
void timestamp ( )
/******************************************************************************/
/*
Purpose:
timestamp prints the current YMDHMS date as a time stamp.
Example:
17 June 2014 09:45:54 AM
Licensing:
This code is distributed under the GNU LGPL license.
Modified:
17 June 2014
Author:
John Burkardt
*/
{
# define TIME_SIZE 40
static char time_buffer[TIME_SIZE];
const struct tm *tm;
time_t now;
now = time ( NULL );
tm = localtime ( &now );
strftime ( time_buffer, TIME_SIZE, "%d %B %Y %I:%M:%S %p", tm );
printf ( "%s\n", time_buffer );
return;
# undef TIME_SIZE
}
euler.rar
版权申诉
34 浏览量
2022-11-13
21:16:20
上传
评论
收藏 1KB RAR 举报
卷积神经网络
- 粉丝: 339
- 资源: 8460
最新资源
- 基于Java和深度学习的瓦斯浓度预测系统后端设计源码 - 瓦斯浓度预测后端
- Screenshot_20240528_103010.jpg
- 基于Python的新能源承载力计算及界面设计源码 - HAINING-DG
- 基于Java的本科探索学习项目设计源码 - 本科探索
- 基于Javascript和Python的微商城项目设计源码 - MicroMall
- 基于Java的网上订餐系统设计源码 - online ordering system
- 基于Javascript的超级美眉网络资源管理应用模块设计源码
- 基于Typescript和PHP的编程知识储备库设计源码 - study-php
- Screenshot_2024-05-28-11-40-58-177_com.tencent.mm.jpg
- 基于Dart的Flutter小提琴调音器APP设计源码 - violinhelper
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈