|
3761 | 3761 | " print()" |
3762 | 3762 | ] |
3763 | 3763 | }, |
3764 | | - { |
3765 | | - "cell_type": "code", |
3766 | | - "execution_count": 64, |
3767 | | - "metadata": {}, |
3768 | | - "outputs": [ |
3769 | | - { |
3770 | | - "name": "stdout", |
3771 | | - "output_type": "stream", |
3772 | | - "text": [ |
3773 | | - "\n", |
3774 | | - "================================================================================\n", |
3775 | | - "Mathematical Problem Solving\n", |
3776 | | - "================================================================================\n", |
3777 | | - "\n", |
3778 | | - "Calculus: Find the derivative of f(x) = (3x² + 2x - 1) * e^x...\n", |
3779 | | - "--------------------------------------------------------------------------------\n", |
3780 | | - "To find the derivative of $f(x) = (3x^2 + 2x - 1) * e^x$, we need to use the **Product Rule**.\n", |
3781 | | - "\n", |
3782 | | - "The Product Rule states that if $f(x) = u(x) * v(x)$, then its derivative $f'(x)$ is given by:\n", |
3783 | | - "$f'(x) = u'(x) * v(x) + u(x) * v'(x)$\n", |
3784 | | - "\n", |
3785 | | - "Let's break down the function $f(x)$ into $u(x)$ and $v(x)$:\n", |
3786 | | - "1. Let $u(x) = 3x^2 + 2x - 1$\n", |
3787 | | - "2. Let $v(x) = e^x$\n", |
3788 | | - "\n", |
3789 | | - "Now, we need to find the derivatives of $u(x)$ and $v(x)$ separately.\n", |
3790 | | - "\n", |
3791 | | - "**Step 1: Find the derivative of u(x), denoted as u'(x).**\n", |
3792 | | - "$u(x) = 3x^2 + 2x - 1$\n", |
3793 | | - "To find $u'(x)$, we apply the Power Rule ($d/dx [x^n] = nx^{n-1}$) and the constant rule ($d/dx [c] = 0$) and the constant multiple rule ($d/dx [cx] = c$).\n", |
3794 | | - "* The derivative of $3x^2$ is $3 * (2x^{2-1}) = 6x$.\n", |
3795 | | - "* The derivative of $2x$ is $2 * (1x^{1-1}) = 2 * 1 = 2$.\n", |
3796 | | - "* The derivative of $-1$ (a constant) is $0$.\n", |
3797 | | - "\n", |
3798 | | - "So, $u'(x) = 6x + 2 + 0$\n", |
3799 | | - "$u'(x) = 6x + 2$\n", |
3800 | | - "\n", |
3801 | | - "**Step 2: Find the derivative of v(x), denoted as v'(x).**\n", |
3802 | | - "$v(x) = e^x$\n", |
3803 | | - "The derivative of $e^x$ is simply $e^x$.\n", |
3804 | | - "\n", |
3805 | | - "So, $v'(x) = e^x$\n", |
3806 | | - "\n", |
3807 | | - "**Step 3: Apply the Product Rule.**\n", |
3808 | | - "Now, substitute $u(x)$, $u'(x)$, $v(x)$, and $v'(x)$ into the Product Rule formula:\n", |
3809 | | - "$f'(x) = u'(x) * v(x) + u(x) * v'(x)$\n", |
3810 | | - "$f'(x) = (6x + 2) * e^x + (3x^2 + 2x - 1) * e^x$\n", |
3811 | | - "\n", |
3812 | | - "**Step 4: Simplify the expression.**\n", |
3813 | | - "Notice that $e^x$ is a common factor in both terms. We can factor it out:\n", |
3814 | | - "$f'(x) = e^x * [(6x + 2) + (3x^2 + 2x - 1)]$\n", |
3815 | | - "\n", |
3816 | | - "Now, combine the like terms inside the square brackets:\n", |
3817 | | - "$f'(x) = e^x * [3x^2 + (6x + 2x) + (2 - 1)]$\n", |
3818 | | - "$f'(x) = e^x * [3x^2 + 8x + 1]$\n", |
3819 | | - "\n", |
3820 | | - "**Final Answer:**\n", |
3821 | | - "The derivative of $f(x) = (3x^2 + 2x - 1) * e^x$ is:\n", |
3822 | | - "$f'(x) = e^x (3x^2 + 8x + 1)$\n", |
3823 | | - "\n", |
3824 | | - "\n", |
3825 | | - "Linear Algebra: Find the eigenvalues of the matrix:\n", |
3826 | | - " [[2, 1...\n", |
3827 | | - "--------------------------------------------------------------------------------\n", |
3828 | | - "To find the eigenvalues of a matrix, we need to solve the characteristic equation, which is given by $\\det(A - \\lambda I) = 0$, where $A$ is the given matrix, $\\lambda$ represents the eigenvalues, and $I$ is the identity matrix of the same dimension as $A$.\n", |
3829 | | - "\n", |
3830 | | - "Given the matrix:\n", |
3831 | | - "$A = \\begin{bmatrix} 2 & 1 \\\\ 1 & 2 \\end{bmatrix}$\n", |
3832 | | - "\n", |
3833 | | - "**Step 1: Form the matrix $(A - \\lambda I)$**\n", |
3834 | | - "\n", |
3835 | | - "First, we need to construct the matrix $(A - \\lambda I)$.\n", |
3836 | | - "The identity matrix $I$ for a 2x2 matrix is $\\begin{bmatrix} 1 & 0 \\\\ 0 & 1 \\end{bmatrix}$.\n", |
3837 | | - "So, $\\lambda I = \\lambda \\begin{bmatrix} 1 & 0 \\\\ 0 & 1 \\end{bmatrix} = \\begin{bmatrix} \\lambda & 0 \\\\ 0 & \\lambda \\end{bmatrix}$.\n", |
3838 | | - "\n", |
3839 | | - "Now, subtract $\\lambda I$ from $A$:\n", |
3840 | | - "$A - \\lambda I = \\begin{bmatrix} 2 & 1 \\\\ 1 & 2 \\end{bmatrix} - \\begin{bmatrix} \\lambda & 0 \\\\ 0 & \\lambda \\end{bmatrix}$\n", |
3841 | | - "$A - \\lambda I = \\begin{bmatrix} 2-\\lambda & 1 \\\\ 1 & 2-\\lambda \\end{bmatrix}$\n", |
3842 | | - "\n", |
3843 | | - "**Step 2: Calculate the determinant of $(A - \\lambda I)$**\n", |
3844 | | - "\n", |
3845 | | - "For a 2x2 matrix $\\begin{bmatrix} a & b \\\\ c & d \\end{bmatrix}$, the determinant is $ad - bc$.\n", |
3846 | | - "Applying this to $(A - \\lambda I)$:\n", |
3847 | | - "$\\det(A - \\lambda I) = (2-\\lambda)(2-\\lambda) - (1)(1)$\n", |
3848 | | - "$\\det(A - \\lambda I) = (2-\\lambda)^2 - 1$\n", |
3849 | | - "\n", |
3850 | | - "Expand the square term:\n", |
3851 | | - "$(2-\\lambda)^2 = 4 - 4\\lambda + \\lambda^2$\n", |
3852 | | - "\n", |
3853 | | - "So, the determinant becomes:\n", |
3854 | | - "$\\det(A - \\lambda I) = \\lambda^2 - 4\\lambda + 4 - 1$\n", |
3855 | | - "$\\det(A - \\lambda I) = \\lambda^2 - 4\\lambda + 3$\n", |
3856 | | - "\n", |
3857 | | - "**Step 3: Solve the characteristic equation**\n", |
3858 | | - "\n", |
3859 | | - "Set the determinant equal to zero to find the eigenvalues:\n", |
3860 | | - "$\\lambda^2 - 4\\lambda + 3 = 0$\n", |
3861 | | - "\n", |
3862 | | - "This is a quadratic equation. We can solve it by factoring, using the quadratic formula, or completing the square.\n", |
3863 | | - "Let's factor the quadratic equation. We need two numbers that multiply to 3 and add up to -4. These numbers are -1 and -3.\n", |
3864 | | - "So, we can factor the equation as:\n", |
3865 | | - "$(\\lambda - 1)(\\lambda - 3) = 0$\n", |
3866 | | - "\n", |
3867 | | - "Setting each factor to zero gives the eigenvalues:\n", |
3868 | | - "$\\lambda - 1 = 0 \\implies \\lambda_1 = 1$\n", |
3869 | | - "$\\lambda - 3 = 0 \\implies \\lambda_2 = 3$\n", |
3870 | | - "\n", |
3871 | | - "**Conclusion:**\n", |
3872 | | - "\n", |
3873 | | - "The eigenvalues of the matrix $\\begin{bmatrix} 2 & 1 \\\\ 1 & 2 \\end{bmatrix}$ are $\\boxed{1 \\text{ and } 3}$.\n", |
3874 | | - "\n", |
3875 | | - "\n", |
3876 | | - "Statistics: Given data: [12, 15, 18, 22, 25, 30, 35]\n", |
3877 | | - " C...\n", |
3878 | | - "--------------------------------------------------------------------------------\n", |
3879 | | - "Let's calculate the mean, median, variance, and standard deviation for the given data step by step.\n", |
3880 | | - "\n", |
3881 | | - "Given data: $[12, 15, 18, 22, 25, 30, 35]$\n", |
3882 | | - "\n", |
3883 | | - "First, let's count the number of data points, $n$.\n", |
3884 | | - "$n = 7$\n", |
3885 | | - "\n", |
3886 | | - "---\n", |
3887 | | - "\n", |
3888 | | - "### Step 1: Calculate the Mean ($\\bar{x}$)\n", |
3889 | | - "\n", |
3890 | | - "The mean is the sum of all data points divided by the number of data points.\n", |
3891 | | - "\n", |
3892 | | - "**Formula:** $\\bar{x} = \\frac{\\sum x}{n}$\n", |
3893 | | - "\n", |
3894 | | - "1. **Sum the data points ($\\sum x$):**\n", |
3895 | | - " $\\sum x = 12 + 15 + 18 + 22 + 25 + 30 + 35 = 157$\n", |
3896 | | - "\n", |
3897 | | - "2. **Divide by the number of data points ($n$):**\n", |
3898 | | - " $\\bar{x} = \\frac{157}{7}$\n", |
3899 | | - " $\\bar{x} \\approx 22.42857...$\n", |
3900 | | - "\n", |
3901 | | - "**Mean ($\\bar{x}$) = 22.43** (rounded to two decimal places)\n", |
3902 | | - "\n", |
3903 | | - "---\n", |
3904 | | - "\n", |
3905 | | - "### Step 2: Calculate the Median\n", |
3906 | | - "\n", |
3907 | | - "The median is the middle value in a dataset when it is ordered from least to greatest.\n", |
3908 | | - "\n", |
3909 | | - "1. **Order the data:**\n", |
3910 | | - " The given data is already ordered: $[12, 15, 18, 22, 25, 30, 35]$\n", |
3911 | | - "\n", |
3912 | | - "2. **Find the position of the median:**\n", |
3913 | | - " Since $n=7$ (an odd number), the median is at the position $\\frac{n+1}{2}$.\n", |
3914 | | - " Position = $\\frac{7+1}{2} = \\frac{8}{2} = 4^{th}$\n", |
3915 | | - "\n", |
3916 | | - "3. **Identify the value at that position:**\n", |
3917 | | - " The 4th value in the ordered list is 22.\n", |
3918 | | - "\n", |
3919 | | - "**Median = 22**\n", |
3920 | | - "\n", |
3921 | | - "---\n", |
3922 | | - "\n", |
3923 | | - "### Step 3: Calculate the Variance ($s^2$)\n", |
3924 | | - "\n", |
3925 | | - "Variance measures how spread out the data points are from the mean. We will calculate the sample variance, which is commonly used when the data is a sample from a larger population.\n", |
3926 | | - "\n", |
3927 | | - "**Formula for Sample Variance:** $s^2 = \\frac{\\sum (x_i - \\bar{x})^2}{n-1}$\n", |
3928 | | - "\n", |
3929 | | - "We will use the more precise value for the mean: $\\bar{x} = \\frac{157}{7}$.\n", |
3930 | | - "\n", |
3931 | | - "1. **Calculate the difference of each data point from the mean ($x_i - \\bar{x}$):**\n", |
3932 | | - " * $12 - \\frac{157}{7} = \\frac{84-157}{7} = -\\frac{73}{7}$\n", |
3933 | | - " * $15 - \\frac{157}{7} = \\frac{105-157}{7} = -\\frac{52}{7}$\n", |
3934 | | - " * $18 - \\frac{157}{7} = \\frac{126-157}{7} = -\\frac{31}{7}$\n", |
3935 | | - " * $22 - \\frac{157}{7} = \\frac{154-157}{7} = -\\frac{3}{7}$\n", |
3936 | | - " * $25 - \\frac{157}{7} = \\frac{175-157}{7} = \\frac{18}{7}$\n", |
3937 | | - " * $30 - \\frac{157}{7} = \\frac{210-157}{7} = \\frac{53}{7}$\n", |
3938 | | - " * $35 - \\frac{157}{7} = \\frac{245-157}{7} = \\frac{88}{7}$\n", |
3939 | | - "\n", |
3940 | | - "2. **Square each of these differences ($(x_i - \\bar{x})^2$):**\n", |
3941 | | - " * $(-\\frac{73}{7})^2 = \\frac{5329}{49}$\n", |
3942 | | - " * $(-\\frac{52}{7})^2 = \\frac{2704}{49}$\n", |
3943 | | - " * $(-\\frac{31}{7})^2 = \\frac{961}{49}$\n", |
3944 | | - " * $(-\\frac{3}{7})^2 = \\frac{9}{49}$\n", |
3945 | | - " * $(\\frac{18}{7})^2 = \\frac{324}{49}$\n", |
3946 | | - " * $(\\frac{53}{7})^2 = \\frac{2809}{49}$\n", |
3947 | | - " * $(\\frac{88}{7})^2 = \\frac{7744}{49}$\n", |
3948 | | - "\n", |
3949 | | - "3. **Sum the squared differences ($\\sum (x_i - \\bar{x})^2$):**\n", |
3950 | | - " $\\sum (x_i - \\bar{x})^2 = \\frac{5329 + 2704 + 961 + 9 + 324 + 2809 + 7744}{49} = \\frac{19880}{49}$\n", |
3951 | | - "\n", |
3952 | | - "4. **Divide by $(n-1)$:**\n", |
3953 | | - " $n-1 = 7-1 = 6$\n", |
3954 | | - " $s^2 = \\frac{\\frac{19880}{49}}{6} = \\frac{19880}{49 \\times 6} = \\frac{19880}{294}$\n", |
3955 | | - " $s^2 \\approx 67.68707...$\n", |
3956 | | - "\n", |
3957 | | - "**Variance ($s^2$) = 67.69** (rounded to two decimal places)\n", |
3958 | | - "\n", |
3959 | | - "---\n", |
3960 | | - "\n", |
3961 | | - "### Step 4: Calculate the Standard Deviation ($s$)\n", |
3962 | | - "\n", |
3963 | | - "The standard deviation is the square root of the variance. It provides a measure of the typical distance of data points from the mean, in the original units of the data.\n", |
3964 | | - "\n", |
3965 | | - "**Formula for Sample Standard Deviation:** $s = \\sqrt{s^2}$\n", |
3966 | | - "\n", |
3967 | | - "1. **Take the square root of the variance:**\n", |
3968 | | - " $s = \\sqrt{\\frac{19880}{294}}$\n", |
3969 | | - " $s = \\sqrt{67.68707...}$\n", |
3970 | | - " $s \\approx 8.22721...$\n", |
3971 | | - "\n", |
3972 | | - "**Standard Deviation ($s$) = 8.23** (rounded to two decimal places)\n", |
3973 | | - "\n", |
3974 | | - "---\n", |
3975 | | - "\n", |
3976 | | - "### Summary of Results:\n", |
3977 | | - "\n", |
3978 | | - "* **Mean ($\\bar{x}$): 22.43**\n", |
3979 | | - "* **Median: 22**\n", |
3980 | | - "* **Variance ($s^2$): 67.69**\n", |
3981 | | - "* **Standard Deviation ($s$): 8.23**\n", |
3982 | | - "\n", |
3983 | | - "\n", |
3984 | | - "Optimization: A rectangular garden has perimeter of 60m.\n", |
3985 | | - " ...\n", |
3986 | | - "--------------------------------------------------------------------------------\n", |
3987 | | - "Here's a step-by-step solution to maximize the area of the rectangular garden:\n", |
3988 | | - "\n", |
3989 | | - "---\n", |
3990 | | - "\n", |
3991 | | - "### Step 1: Understand the Problem and Define Variables\n", |
3992 | | - "\n", |
3993 | | - "* **Goal:** Maximize the area of a rectangular garden.\n", |
3994 | | - "* **Constraint:** The perimeter of the garden is fixed at 60 meters.\n", |
3995 | | - "* **Unknowns:** The dimensions (length and width) of the rectangle.\n", |
3996 | | - "\n", |
3997 | | - "Let:\n", |
3998 | | - "* `L` be the length of the garden (in meters)\n", |
3999 | | - "* `W` be the width of the garden (in meters)\n", |
4000 | | - "* `P` be the perimeter of the garden (in meters)\n", |
4001 | | - "* `A` be the area of the garden (in square meters)\n", |
4002 | | - "\n", |
4003 | | - "---\n", |
4004 | | - "\n", |
4005 | | - "### Step 2: Formulate Equations Based on the Given Information\n", |
4006 | | - "\n", |
4007 | | - "We know the standard formulas for the perimeter and area of a rectangle:\n", |
4008 | | - "\n", |
4009 | | - "1. **Perimeter Formula:** $P = 2L + 2W$\n", |
4010 | | - " * Given $P = 60m$, so:\n", |
4011 | | - " $60 = 2L + 2W$\n", |
4012 | | - "\n", |
4013 | | - "2. **Area Formula:** $A = L \\times W$\n", |
4014 | | - " * This is the function we want to maximize.\n", |
4015 | | - "\n", |
4016 | | - "---\n", |
4017 | | - "\n", |
4018 | | - "### Step 3: Express Area as a Function of a Single Variable\n", |
4019 | | - "\n", |
4020 | | - "To maximize the area, we need to express the area equation in terms of only one variable (either L or W). We can use the perimeter equation for this.\n", |
4021 | | - "\n", |
4022 | | - "From the perimeter equation:\n", |
4023 | | - "$60 = 2L + 2W$\n", |
4024 | | - "\n", |
4025 | | - "Divide the entire equation by 2:\n", |
4026 | | - "$30 = L + W$\n", |
4027 | | - "\n", |
4028 | | - "Now, solve for one variable (let's solve for L):\n", |
4029 | | - "$L = 30 - W$\n", |
4030 | | - "\n", |
4031 | | - "Substitute this expression for `L` into the Area formula:\n", |
4032 | | - "$A = (30 - W) \\times W$\n", |
4033 | | - "$A(W) = 30W - W^2$\n", |
4034 | | - "\n", |
4035 | | - "Now we have the area `A` as a function of only the width `W`. This is a quadratic function, which graphs as a parabola opening downwards (due to the -W² term), meaning it has a maximum point.\n", |
4036 | | - "\n", |
4037 | | - "---\n", |
4038 | | - "\n", |
4039 | | - "### Step 4: Find the Maximum Area Using Calculus (Derivative)\n", |
4040 | | - "\n", |
4041 | | - "To find the value of `W` that maximizes `A(W)`, we take the first derivative of `A(W)` with respect to `W` and set it equal to zero.\n", |
4042 | | - "\n", |
4043 | | - "$A(W) = 30W - W^2$\n", |
4044 | | - "\n", |
4045 | | - "Find the first derivative $A'(W)$:\n", |
4046 | | - "$A'(W) = \\frac{d}{dW}(30W - W^2)$\n", |
4047 | | - "$A'(W) = 30 - 2W$\n", |
4048 | | - "\n", |
4049 | | - "Set the derivative to zero to find critical points (where the slope of the tangent line is zero, indicating a potential maximum or minimum):\n", |
4050 | | - "$30 - 2W = 0$\n", |
4051 | | - "\n", |
4052 | | - "Solve for `W`:\n", |
4053 | | - "$30 = 2W$\n", |
4054 | | - "$W = \\frac{30}{2}$\n", |
4055 | | - "$W = 15$ meters\n", |
4056 | | - "\n", |
4057 | | - "---\n", |
4058 | | - "\n", |
4059 | | - "### Step 5: Calculate the Other Dimension (Length)\n", |
4060 | | - "\n", |
4061 | | - "Now that we have the optimal width `W`, we can find the corresponding length `L` using the relationship we established in Step 3:\n", |
4062 | | - "\n", |
4063 | | - "$L = 30 - W$\n", |
4064 | | - "$L = 30 - 15$\n", |
4065 | | - "$L = 15$ meters\n", |
4066 | | - "\n", |
4067 | | - "---\n", |
4068 | | - "\n", |
4069 | | - "### Step 6: Verify the Maximum Area and State the Conclusion\n", |
4070 | | - "\n", |
4071 | | - "The dimensions that maximize the area are:\n", |
4072 | | - "* Length `L` = 15 meters\n", |
4073 | | - "* Width `W` = 15 meters\n", |
4074 | | - "\n", |
4075 | | - "Let's calculate the maximum area:\n", |
4076 | | - "$A = L \\times W$\n", |
4077 | | - "$A = 15 \\times 15$\n", |
4078 | | - "$A = 225$ square meters\n", |
4079 | | - "\n", |
4080 | | - "We can also quickly check the perimeter: $P = 2(15) + 2(15) = 30 + 30 = 60m$, which matches the given constraint.\n", |
4081 | | - "\n", |
4082 | | - "**Conclusion:**\n", |
4083 | | - "\n", |
4084 | | - "The dimensions that maximize the area of a rectangular garden with a perimeter of 60m are **15 meters by 15 meters**. This means the garden should be a square. The maximum area achieved is **225 square meters**.\n", |
4085 | | - "\n" |
4086 | | - ] |
4087 | | - } |
4088 | | - ], |
4089 | | - "source": [ |
4090 | | - "print(\"\\n\" + \"=\"*80)\n", |
4091 | | - "print(\"Mathematical Problem Solving\")\n", |
4092 | | - "print(\"=\"*80)\n", |
4093 | | - "\n", |
4094 | | - "math_problems = [\n", |
4095 | | - " {\n", |
4096 | | - " \"type\": \"Calculus\",\n", |
4097 | | - " \"problem\": \"Find the derivative of f(x) = (3x² + 2x - 1) * e^x\"\n", |
4098 | | - " },\n", |
4099 | | - " {\n", |
4100 | | - " \"type\": \"Linear Algebra\",\n", |
4101 | | - " \"problem\": \"\"\"Find the eigenvalues of the matrix:\n", |
4102 | | - " [[2, 1],\n", |
4103 | | - " [1, 2]]\"\"\"\n", |
4104 | | - " },\n", |
4105 | | - " {\n", |
4106 | | - " \"type\": \"Statistics\",\n", |
4107 | | - " \"problem\": \"\"\"Given data: [12, 15, 18, 22, 25, 30, 35]\n", |
4108 | | - " Calculate: mean, median, variance, and standard deviation\"\"\"\n", |
4109 | | - " },\n", |
4110 | | - " {\n", |
4111 | | - " \"type\": \"Optimization\",\n", |
4112 | | - " \"problem\": \"\"\"A rectangular garden has perimeter of 60m.\n", |
4113 | | - " What dimensions maximize the area?\"\"\"\n", |
4114 | | - " }\n", |
4115 | | - "]\n", |
4116 | | - "\n", |
4117 | | - "for prob in math_problems:\n", |
4118 | | - " prompt = f\"\"\"Solve this {prob['type']} problem step by step:\n", |
4119 | | - "\n", |
4120 | | - "{prob['problem']}\n", |
4121 | | - "\n", |
4122 | | - "Show all work and explain each step.\"\"\"\n", |
4123 | | - "\n", |
4124 | | - " response = client.models.generate_content(\n", |
4125 | | - " model=\"gemini-2.0-flash-thinking-exp-1219\",\n", |
4126 | | - " contents=prompt\n", |
4127 | | - " )\n", |
4128 | | - " print(f\"\\n{prob['type']}: {prob['problem'][:50]}...\")\n", |
4129 | | - " print(\"-\" * 80)\n", |
4130 | | - " print(response.text)\n", |
4131 | | - " print()" |
4132 | | - ] |
4133 | | - }, |
4134 | 3764 | { |
4135 | 3765 | "cell_type": "markdown", |
4136 | 3766 | "metadata": {}, |
|
0 commit comments