Batasheva Durdonaning
Download 377.6 Kb.
|
1-amalily AL
Muhammad al-Xorazmiy nomidagi Toshkent axborot texnologiyalari universiteti Televizion texnologiyalar/Audiovizual texnologiyalari fakulteti 512-20 guruh talabasi Batasheva Durdonaning Algaritmlarni loyihalash fanidan 1-amaliy ishi Bajardi: Batasheva Durdona. Tekshirdi: Begimov O’ktam. 4-variant: #include #include #define f(x) log(pow(x,2)+3)*pow(sin(x+1),2) using namespace std; int main() { float lower, upper, integration=0.0, stepSize, k; int i, subInterval; cout<<"Enter lower limit of integration: "; cin>>lower; cout<<"Enter upper limit of integration: "; cin>>upper; cout<<"Enter number of sub intervals: "; cin>>subInterval; stepSize = (upper - lower)/subInterval; integration = f(lower) + f(upper); for(i=1; i<= subInterval-1; i++)
integration = integration * stepSize/2; cout<< endl<<"Required value of integration is: "<< integration; return 0; } Dastur Natijasi 2. #include #include using namespace std; #define MAX_ITER 1000000 double func(double x) { return x-cos(x); } void regulaFalsi(double a, double b) { if(func(a)*func(b) >= 0) { cout << " You have not assumed right a and b\n"; return; } double c = a; for(int i = 0; i < MAX_ITER; i ++) { c = (a*func(b) - b*func(a)) / (func(b)-func(a)); if(func(c) == 0) break; else if(func(c)*func(a) < 0) b = c; else a = c; } cout << "The value of root is : " << c; } int main() { double a = 0, b = 1; regulaFalsi(a, b); return 0; } b) #include #include using namespace std; #define MAX_ITER 1000000 double func(double x) { return x*x*x+3*x-1; } void regulaFalsi(double a, double b) { if(func(a)*func(b) >= 0) { cout << " You have not assumed right a and b\n"; return; } double c = a; for(int i = 0; i < MAX_ITER; i ++) { c = (a*func(b) - b*func(a)) / (func(b)-func(a)); if(func(c) == 0) break; else if(func(c)*func(a) < 0) b = c; else a = c; } cout << "The value of root is : " << c; } int main() { double a = 0, b = 1; regulaFalsi(a, b); return 0; } 3-savol [Forwarded from Durov] from cmath import log import numpy as np def newton(f,Df,x0,epsilon,max_iter): xn = x0 for n in range(0,max_iter): fxn = f(xn) if abs(fxn) < epsilon: print(f'{n} ta iteratsiyadan song topilgan javoblar: ') return xn Dfxn = Df(xn) if Dfxn == 0: print('Xosila nol, yechim topilmadi.') return None xn = xn - fxn/Dfxn print('Iteratsiya maximal dan oshib ketdi, yechim topilmadi') return None p = lambda x: x - np.cos(x) Dp = lambda x: 1 + np.sin(x) approx = newton(p,Dp,1,1e-3,10) print(approx) ''' p = lambda x: x**3 + 3*x - 1 Dp = lambda x: 3*x**2 + 3 approx = newton(p,Dp,1,1e-3,10) print(approx) ''' Dastur NAtijasi Download 377.6 Kb. Do'stlaringiz bilan baham: |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling