An warware: wanda ya samo asali na pytorch mai aiki da yawa

wanda aka samu na multivariable ayyuka 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.

Shafi posts:

Leave a Comment