Matlab coding problem.
Having trouble wrapping my head around this one.
Im posting multiple times to get different answers. If you have answered this already, please ignore. i want several different answers so i can better learn



Problem (same as lab, but without using fzero): In chemistry and thermodynamics the Van der Waal's equation is often used to describe the behavior of a gas: \[ \left(p+\frac{n^{2} a}{v^{2}}\right)(v-n b)=n R T \] where \( \mathrm{a} \) and \( \mathrm{b} \) are constants specific to the gas and \( \mathrm{R} \) is the universal gas constant. For our greenhouse gas, carbon dioxide, these constants equal: \[ \begin{array}{l} \mathrm{a}=3.640 \mathrm{~atm} \mathrm{~mol}^{2} / \mathrm{L}^{2} \\ \mathrm{~b}=0.04267 \mathrm{~L} / \mathrm{mol} \\ \mathrm{R}=0.082054 \mathrm{~L} \mathrm{~atm} /(\mathrm{mol} \mathrm{K}) \\ \mathrm{n}=1 \mathrm{~mol} \end{array} \] For a variety of \( \mathrm{p} \) (pressure) and \( \mathrm{T} \) (temperature) values, we can solve the formula to get \( \mathrm{v} \) (the molal volume). We are going to use a root finding to create a program that will automatically solve this problem. First we create the function: \[ f(v)=\left(p+\frac{n^{2} a}{v^{2}}\right)(v-n b)-n R T \] \( f(v) \) should equal zero. Using root finding methods we can locate the value of \( v \) for which \( f(v)= \) 0.
Task: 1. Write a function that returns \( f(v) \) given \( v, a, b, R, T, p \). The value of \( v \) should be passed to the function. The other values should be global variables. 2. Write a function that uses the bisection root finding methods to solve \( f(\mathrm{v})=0 \). This function should call the function from task 1 to get the value of \( f(v) \). 3. Write a script that creates two vectors for values of pressure between 1 and \( 1000 \mathrm{~atm} \) and Temperatures between 200 and \( 800 \mathrm{~K} \) using the code: pvect \( = \) logspace \( (1,3,20) \); Tvect \( = \) linspace \( (300,800,20) ; \)
At the beginning of the script create global variable for current pressure (p) and temperature \( (\mathrm{T}) \). Then create a set of nested loops in which your secant function is called for each combination of pressure and temperature. In the script, create a surface 3-D plot of the data. To do this you need to have two vectors representing the \( p \) values and the \( T \) values and a matrix representing the corresponding volumes. surf(pvect,Tvect, \( \mathrm{v}) \) view \( (50,-14) \)