|
272 | 272 | "dy = 1 + 2*x\n", |
273 | 273 | "print(dy)" |
274 | 274 | ] |
275 | | - }, |
276 | | - { |
277 | | - "cell_type": "markdown", |
278 | | - "id": "84566773-1eb4-4bc2-87a4-dbc88ea70d76", |
279 | | - "metadata": {}, |
280 | | - "source": [ |
281 | | - "## Mathematical Functions\n", |
282 | | - "\n", |
283 | | - "All the standard mathematical functions are available in NumPy:\n", |
284 | | - "\n", |
285 | | - "| Function | NumPy Syntax |\n", |
286 | | - "| :---: | :---: |\n", |
287 | | - "| $\\sin(x)$ | `np.sin(x)` |\n", |
288 | | - "| $\\cos(x)$ | `np.cos(x)` |\n", |
289 | | - "| $\\tan(x)$ | `np.tan(x)` |\n", |
290 | | - "| $\\tan^{-1}(x)$ | `np.arctan(x)` |\n", |
291 | | - "| $e^x$ | `np.exp(x)` |\n", |
292 | | - "| $\\ln(x)$ | `np.log(x)` |\n", |
293 | | - "| $\\log_{10}(x)$ | `np.log10(x)` |\n", |
294 | | - "| $\\sqrt{x}$ | `np.sqrt(x)` |\n", |
295 | | - "\n", |
296 | | - "Let's compute some examples:" |
297 | | - ] |
298 | | - }, |
299 | | - { |
300 | | - "cell_type": "code", |
301 | | - "execution_count": 22, |
302 | | - "id": "f2878313-b169-43f9-9c5f-bb59a66711a5", |
303 | | - "metadata": { |
304 | | - "tags": [] |
305 | | - }, |
306 | | - "outputs": [ |
307 | | - { |
308 | | - "data": { |
309 | | - "text/plain": [ |
310 | | - "0.7071067811865476" |
311 | | - ] |
312 | | - }, |
313 | | - "execution_count": 22, |
314 | | - "metadata": {}, |
315 | | - "output_type": "execute_result" |
316 | | - } |
317 | | - ], |
318 | | - "source": [ |
319 | | - "np.cos(np.pi/4)" |
320 | | - ] |
321 | | - }, |
322 | | - { |
323 | | - "cell_type": "code", |
324 | | - "execution_count": 23, |
325 | | - "id": "8a283317-4c79-48ad-98d4-aa937348bf45", |
326 | | - "metadata": { |
327 | | - "tags": [] |
328 | | - }, |
329 | | - "outputs": [ |
330 | | - { |
331 | | - "data": { |
332 | | - "text/plain": [ |
333 | | - "0.7071067811865475" |
334 | | - ] |
335 | | - }, |
336 | | - "execution_count": 23, |
337 | | - "metadata": {}, |
338 | | - "output_type": "execute_result" |
339 | | - } |
340 | | - ], |
341 | | - "source": [ |
342 | | - "1/np.sqrt(2)" |
343 | | - ] |
344 | | - }, |
345 | | - { |
346 | | - "cell_type": "code", |
347 | | - "execution_count": 24, |
348 | | - "id": "edd24472-840f-4e87-9a16-361dd7069e2d", |
349 | | - "metadata": { |
350 | | - "tags": [] |
351 | | - }, |
352 | | - "outputs": [ |
353 | | - { |
354 | | - "data": { |
355 | | - "text/plain": [ |
356 | | - "0.6931471805599453" |
357 | | - ] |
358 | | - }, |
359 | | - "execution_count": 24, |
360 | | - "metadata": {}, |
361 | | - "output_type": "execute_result" |
362 | | - } |
363 | | - ], |
364 | | - "source": [ |
365 | | - "np.log(2)" |
366 | | - ] |
367 | | - }, |
368 | | - { |
369 | | - "cell_type": "code", |
370 | | - "execution_count": 26, |
371 | | - "id": "a7360663-65c5-4377-b2f2-4d41813baa35", |
372 | | - "metadata": { |
373 | | - "tags": [] |
374 | | - }, |
375 | | - "outputs": [ |
376 | | - { |
377 | | - "data": { |
378 | | - "text/plain": [ |
379 | | - "0.7853981633974483" |
380 | | - ] |
381 | | - }, |
382 | | - "execution_count": 26, |
383 | | - "metadata": {}, |
384 | | - "output_type": "execute_result" |
385 | | - } |
386 | | - ], |
387 | | - "source": [ |
388 | | - "np.arctan(1)" |
389 | | - ] |
390 | | - }, |
391 | | - { |
392 | | - "cell_type": "code", |
393 | | - "execution_count": 27, |
394 | | - "id": "8f2fcd44-5770-4ce2-ad0a-ae86bc742c99", |
395 | | - "metadata": { |
396 | | - "tags": [] |
397 | | - }, |
398 | | - "outputs": [ |
399 | | - { |
400 | | - "data": { |
401 | | - "text/plain": [ |
402 | | - "0.3010299956639812" |
403 | | - ] |
404 | | - }, |
405 | | - "execution_count": 27, |
406 | | - "metadata": {}, |
407 | | - "output_type": "execute_result" |
408 | | - } |
409 | | - ], |
410 | | - "source": [ |
411 | | - "np.log10(2)" |
412 | | - ] |
413 | | - }, |
414 | | - { |
415 | | - "cell_type": "code", |
416 | | - "execution_count": 28, |
417 | | - "id": "80592a00-61ad-4473-a2e0-cefb431ecbcd", |
418 | | - "metadata": { |
419 | | - "tags": [] |
420 | | - }, |
421 | | - "outputs": [ |
422 | | - { |
423 | | - "data": { |
424 | | - "text/plain": [ |
425 | | - "2.0" |
426 | | - ] |
427 | | - }, |
428 | | - "execution_count": 28, |
429 | | - "metadata": {}, |
430 | | - "output_type": "execute_result" |
431 | | - } |
432 | | - ], |
433 | | - "source": [ |
434 | | - "10**0.3010299956639812" |
435 | | - ] |
436 | | - }, |
437 | | - { |
438 | | - "cell_type": "markdown", |
439 | | - "id": "90b77e2c-8c79-4d07-a9c7-790990db361b", |
440 | | - "metadata": {}, |
441 | | - "source": [ |
442 | | - "## Custom Functions\n", |
443 | | - "\n", |
444 | | - "Create custom functions using the `lambda` keyword. For example, let's create the function:\n", |
445 | | - "\n", |
446 | | - "$$\n", |
447 | | - "f(x) = \\frac{1}{1 + x^2}\n", |
448 | | - "$$" |
449 | | - ] |
450 | | - }, |
451 | | - { |
452 | | - "cell_type": "code", |
453 | | - "execution_count": 29, |
454 | | - "id": "5033800c-5425-48fc-a9fe-520f4744e578", |
455 | | - "metadata": { |
456 | | - "tags": [] |
457 | | - }, |
458 | | - "outputs": [], |
459 | | - "source": [ |
460 | | - "f = lambda x: 1/(1 + x**2)" |
461 | | - ] |
462 | | - }, |
463 | | - { |
464 | | - "cell_type": "markdown", |
465 | | - "id": "cb6f8769-4731-44fa-a444-83f12fbf6316", |
466 | | - "metadata": {}, |
467 | | - "source": [ |
468 | | - "Compute some values of $f(x)$:" |
469 | | - ] |
470 | | - }, |
471 | | - { |
472 | | - "cell_type": "code", |
473 | | - "execution_count": 30, |
474 | | - "id": "4ac74bd9-130c-4d93-b35d-44e7b391376c", |
475 | | - "metadata": { |
476 | | - "tags": [] |
477 | | - }, |
478 | | - "outputs": [ |
479 | | - { |
480 | | - "data": { |
481 | | - "text/plain": [ |
482 | | - "1.0" |
483 | | - ] |
484 | | - }, |
485 | | - "execution_count": 30, |
486 | | - "metadata": {}, |
487 | | - "output_type": "execute_result" |
488 | | - } |
489 | | - ], |
490 | | - "source": [ |
491 | | - "f(0)" |
492 | | - ] |
493 | | - }, |
494 | | - { |
495 | | - "cell_type": "code", |
496 | | - "execution_count": 31, |
497 | | - "id": "57c4bd22-3064-4546-a400-dcbdab424d89", |
498 | | - "metadata": { |
499 | | - "tags": [] |
500 | | - }, |
501 | | - "outputs": [ |
502 | | - { |
503 | | - "data": { |
504 | | - "text/plain": [ |
505 | | - "0.5" |
506 | | - ] |
507 | | - }, |
508 | | - "execution_count": 31, |
509 | | - "metadata": {}, |
510 | | - "output_type": "execute_result" |
511 | | - } |
512 | | - ], |
513 | | - "source": [ |
514 | | - "f(1)" |
515 | | - ] |
516 | | - }, |
517 | | - { |
518 | | - "cell_type": "code", |
519 | | - "execution_count": 32, |
520 | | - "id": "8cabfb40-2d2c-46ea-8154-5e57445eb0c8", |
521 | | - "metadata": { |
522 | | - "tags": [] |
523 | | - }, |
524 | | - "outputs": [ |
525 | | - { |
526 | | - "data": { |
527 | | - "text/plain": [ |
528 | | - "0.2" |
529 | | - ] |
530 | | - }, |
531 | | - "execution_count": 32, |
532 | | - "metadata": {}, |
533 | | - "output_type": "execute_result" |
534 | | - } |
535 | | - ], |
536 | | - "source": [ |
537 | | - "f(2)" |
538 | | - ] |
539 | 275 | } |
540 | 276 | ], |
541 | 277 | "metadata": { |
|
0 commit comments