• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

关于python:python语法

python 搞代码 3年前 (2022-02-20) 15次浏览 已收录 0个评论

Assignment_2
October 14, 2021
1 Lab Assignment 2

1.1 Presentation and coding style (3 marks)
In this assignment, some marks are allocated to your coding style and presentation. Try to make
your code more readable using the tips given in your computer lab 2. Make sure your figures have
good quality, right size, good range and proper labels.
1.2 Task 1 (4 marks)
In this task we try to use several method from Lab 2 to solve the initial value problem
y
′ = 3y − 4t, y(0) = 1, (1)
Set the step size to h = 0.05 and numerically solve this ODE from t = 0 to 0.5 using the following
methods:
• Forward Euler
• Adams–Bashforth order 2
• Adams–Bashforth order 3 (we did not code this method in the computer lab, but you can
find the formula on this wikipedia page). For this method, you need to build the very first
two steps using other methods. For the first step, use the Euler scheme. For the second step,
use Adams–Bashforth order 2.
Plot the three different approximations, and display the values in a table.

import math
import numpy as np
import matplotlib.pyplot as plt

plot the results

1

1.3 Task 2 (3 marks)
Use SymPy to solve the differential equation y
′ = 3y − 4t, with y(0) = 1, present the analytical
solution, and check the exact value of y(0.5).
Compare the result with the approximations from the three methods in Task 1. You may use a
table to show the results of each method at y(0.5). Which method is the most/least accurate?
Why?

import sympy as sym
sym.init_printing()
from IPython.display import display_latex
import sympy.plotting as sym_plot


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:关于python:python语法
喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址