Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Numeric Analysis Engineering, Assignments of Mathematical Methods for Numerical Analysis and Optimization

euler method modified euler method runge kutte

Typology: Assignments

2023/2024

Uploaded on 03/26/2024

yasir-malkoc
yasir-malkoc 🇹🇷

1 document

1 / 9

Related documents


Partial preview of the text

Download Numeric Analysis Engineering and more Assignments Mathematical Methods for Numerical Analysis and Optimization in PDF only on Docsity! # -*- coding: utf-8 -*- """ Created on Fri Mar 15 15:15:44 2024 @author: """ import numpy as np from matplotlib import pyplot as plt import math # u'=0.5(x-u) # i-) Euler Yöntemi; h= 0.25 ve h=0.1; 0<=x<=1 # u(0)=1 # u(x+h)=u(x)+u'(x)*h # h=0.25 için h1=0.25 x= np.arange(0,1.00001,h1) u = np.zeros(len(x)) u[0]=1 for i in range(0, len(x) - 1): u[i + 1] = u[i] + h1*0.5*(x[i]-u[i]) print("") print('_' * 30) print("") print("EULER YÖNTEMİ") print("") print("") print("h=0.25 için") print("") for i in range(len(u)): print("u(",x[i],")=",u[i]) print("") print('_' * 30) print("") plt.plot(x, u,'g-') plt.grid plt.xlabel('x values') plt.ylabel('u values') plt.title('EULER YÖNTEMİ-h=0.25') plt.tight_layout() plt.show() # h=0.1 için h2=0.1 x1= np.arange(0,1.00001,h2) u1 = np.zeros(len(x1)) u1[0]=1 for i in range(0, len(x1) - 1): u1[i + 1] = u1[i] + h2*0.5*(x1[i]-u1[i]) print("") print('_' * 30) print("") print("EULER YÖNTEMİ") print("") print("") print("h=0.1 için") print("") for i in range(len(u1)): print("u(",round(x1[i],2),")=",u1[i]) print("") print('_' * 30) print("") plt.plot(x1, u1,'g-') plt.grid plt.xlabel('x values') print("") for i in range(len(u4)): print("u(",round(x1[i],2),")=",u4[i]) print("") print('_' * 30) print("") plt.plot(x1, u4,'g-') plt.grid plt.xlabel('x values') plt.ylabel('u values') plt.title('MODİFİYE EULER YÖNTEMİ-h=0.1') plt.tight_layout() plt.show() # aynı grafikte plt.plot(x, u3,label='h=0.25 için') plt.plot(x1, u4, label='h=0.1 için') plt.grid plt.xlabel('x values') plt.ylabel('u values') plt.title('MODİFİYE EULER YÖNTEMİ-h=0.25 ve h=0.1 için') plt.tight_layout() plt.legend() plt.show() # iii-) Dördüncü Derece Runge-Kutta Yöntemi; h= 0.25 ve h=0.1 # h=0.25 için x= np.arange(0,1.00001,h1) u5 = np.zeros(len(x)) u5[0]=1 k11=np.zeros(len(x)) k22=np.zeros(len(x)) k33=np.zeros(len(x)) k44=np.zeros(len(x)) for i in range(0, len(x) - 1): k11[i]=0.5*(x[i]-u5[i]) k22[i]=((0.5*h1+x[i])-(u5[i]+0.5*h1*k11[i]))*0.5 k33[i]=((0.5*h1+x[i])-(u5[i]+0.5*h1*k22[i]))*0.5 k44[i]=0.5*((x[i]+h1)-(u5[i]+k33[i]*h1)) u5[i+1]=u5[i]+(k11[i]+2*k22[i]+2*k33[i]+k44[i])*h1/6 print("") print('_' * 30) print("") print("Dördüncü Derece Runge-Kutta Yöntemi") print("") print("") print("h=0.25 için") print("") for i in range(len(u5)): print("u(",x[i],")=",u5[i]) print("") print('_' * 30) print("") plt.plot(x, u5,'g-') plt.grid plt.xlabel('x values') plt.ylabel('u values') plt.title('Dördüncü Derece Runge-Kutta Yöntemi-h=0.25') plt.tight_layout() plt.show() # h=0.1 için x1= np.arange(0,1.00001,h2) u6 = np.zeros(len(x1)) u6[0]=1 k1_1=np.zeros(len(x1)) k2_2=np.zeros(len(x1)) k3_3=np.zeros(len(x1)) k4_4=np.zeros(len(x1)) for i in range(0, len(x1) - 1): k1_1[i]=0.5*(x1[i]-u6[i]) k2_2[i]=((0.5*h2+x1[i])-(u6[i]+0.5*h2*k1_1[i]))*0.5 k3_3[i]=((0.5*h2+x1[i])-(u6[i]+0.5*h2*k2_2[i]))*0.5 k4_4[i]=0.5*((x1[i]+h2)-(u6[i]+k3_3[i]*h2)) u6[i+1]=u6[i]+(k1_1[i]+2*k2_2[i]+2*k3_3[i]+k4_4[i])*h2/6 print("") print('_' * 30) print("") print("Dördüncü Derece Runge-Kutta Yöntemi") print("") print("") print("h=0.1 için") print("") for i in range(len(u6)): print("u(",round(x1[i],2),")=",u6[i]) print("") print('_' * 30) print("") plt.plot(x1, u6,'g-') plt.grid plt.xlabel('x values') plt.ylabel('u values') plt.title('Dördüncü Derece Runge-Kutta Yöntemi-h=0.1') plt.tight_layout() plt.show() # aynı grafikte plt.plot(x, u5,label='h=0.25 için')
Docsity logo



Copyright © 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved