Nazarin da nazarin ayyukan lissafi wani muhimmin al'amari ne na fannoni daban-daban, gami da aikin injiniya, kimiyyar lissafi, da kimiyyar kwamfuta. Musamman, abubuwan da suka samo asali na ayyuka masu yawa suna da aikace-aikace da yawa kuma suna taka muhimmiyar rawa wajen fahimtar halaye da kaddarorin waษannan ayyuka. Wannan labarin yana nufin samar da zurfin bincike game da samuwar ayyuka masu yawa a cikin mahallin shirye-shiryen Python. Za mu yi nazarin misali-hannun-on misali, yin bayanin kowane mataki na tsari da mahimman abubuwan da ke tattare da samun aiki mai iya canzawa.
Matsala: Samar da Aiki Mai Daban-daban
A fagen lissafi, aiki mai iya canzawa shine wanda ya dogara da mabambanta fiye da ษaya. Don fara aiki tare da irin wannan aikin, da farko muna buฦatar fahimtar manufar abubuwan ban sha'awa. ฦarฦashin ษangarori shine abin da ya samo asali na aiki mai iya canzawa dangane da mai canzawa ษaya, yana kula da duk sauran masu canji a matsayin masu canzawa. Ana kiran tsarin gano ษangarori daban-daban masu alaฦa da kowane maษaukaki da ke da hannu a cikin aiki mai yawa samuwar aikin multivariable.
Bari mu yi la'akari da misali don mafi kyawun kwatanta manufar. Muna da aiki:
โโ
f(x, y) = 3x^2*y + x*y^2
โโ
Manufarmu ita ce nemo abin da aka samo asali game da x (โf/โx) da kuma abin da ya shafi y (โf/โy).
Maganin Python don Samar da Aiki Mai Sauri
Don ฦididdige abubuwan da suka samo asali a cikin Python, za mu yi amfani da ษakin karatu mai ฦarfi SymPy, wanda ke ba da ฦaฦฦarfan yanayi don lissafi na alama.
Da farko, muna buฦatar shigar da ษakin karatu ta amfani da pip:
โโ
pip shigar sympy
โโ
Yanzu, zamu iya rubuta shirin Python don ฦididdige abubuwan da suka samo asali:
import sympy as sp x, y = sp.symbols('x y') f = 3*x**2*y + x*y**2 partial_derivative_x = sp.diff(f, x) partial_derivative_y = sp.diff(f, y) print("โf/โx:", partial_derivative_x) print("โf/โy:", partial_derivative_y)
Bayan aiwatar da lambar, za mu sami abubuwan ban sha'awa:
โโ
โf/โx: 6*x*y + y**2
โf/โy: 3*x**2 + 2*x*y
โโ
Bayanin mataki-mataki na Code
1. Da farko, muna shigo da ษakin karatu na SymPy:
"'shigo da tausayi kamar sp"'
2. Na gaba, muna ayyana masu canji x da y a matsayin alamomi:
"'x, y = sp.alamomi('x y')"'
3. Sa'an nan, mun ayyana aikin multivariable f(x, y):
โ`f = 3*x**2*y + x*y*2โ`
4. Bayan ayyana aikin, za mu ci gaba da ฦididdige abubuwan ban sha'awa game da x da y:
โโ
partial_derivative_x = sp.diff(f, x)
partial_derivative_y = sp.diff(f, y)
โโ
5. A ฦarshe, muna buga sakamakon:
โโ
buga ("โf/โx:", partial_derivative_x)
buga ("โf/โy:", partial_derivative_y)
โโ
Laburaren SymPy: Kayan aiki mai ฦarfi don Lissafin Alama
The SymPy library kayan aiki ne mai mahimmanci ga duk wanda ke aiki da lissafi na alama a Python. Yana ba da damar sarrafa maganganun lissafi mara kyau, sauฦaฦawa, warware daidaito, da ฦari mai yawa. A cikin misalinmu, mun yi amfani da SymPy don ฦididdige abubuwan ban sha'awa, amma ฦarfinsa ya wuce hakan.
- Maganin Magana: Gyara maganganun lissafi ta hanyar alama, ba da damar ayyuka daban-daban kamar musanyawa, haษakawa, da ฦima.
- Sauฦaฦe: Sauฦaฦe rikitattun maganganu zuwa mafi ฦarancin tsari ko canza su zuwa takamaiman tsari.
- Magance Equation: Warware ma'auni na algebra a alamance, gami da layin layi, da yawa, da tsarin daidaitawa.
- ฦwararren Lissafi: Yi ayyuka masu alaฦa da haษin kai, ka'idar jadawali, da ka'idar lamba.
A ฦarshe, fahimtar ma'anar abubuwan da aka samo asali a cikin ayyuka masu yawa, tare da amfani da Python da ษakin karatu na SymPy, yana da nau'o'in aikace-aikace masu yawa a fannoni kamar aikin injiniya, kimiyyar lissafi, da kimiyyar kwamfuta. Sanin kanku da waษannan kayan aikin na iya haษaka ikon ku na tinkarar ฦalubalen ilmin lissafi da haษaka ฦwarewar ku wajen warware matsala.