Question

In: Computer Science

Write a MATLAB script file to numerically solve any first order initial value problem using Rulers...

Write a MATLAB script file to numerically solve any first order initial value problem using Rulers method. Once code is working use it to solve the mixing tank problem below. Use a step size of 1 minute, and simulate the solution until the tank contains no more salt. Plot both the Euler approximation and the exact solution on the same set of axes.

A tank contains 100 gallons of fresh water. At t=0 minutes, a solution containing 1 lb/gal of brine is pumped into the tank at a rate of 1 gal/min. while the mixture is pumped out at a rate of 2 gal/min. Model the corresponding initial value problem, and then determine the amount of salt in the tank as a function of time until the tank is empty.

Solutions

Expert Solution

Let y be the concentration of salt. Hence the rate at which the concentration varies can be expressed as

with

Hence the ODE can be written as

Solve for y

Apply initial conditions y(0) = 0

at t =100 y will be zero

Matlab code

f = @(y,t) 1-2*y/(100-t); % The rhs function
h = 1; % step size
t = 0:h:100; % the t vector [0,100] with an increment h= 1
y(1) = 0; % initial condition
for k =2:length(t)% loop for computing y
    y(k) = y(k-1)+h*f(y(k-1),t(k-1)); % computing the solution at each step
end
plot(t,y);% plotting y vs t with h =1
hold on; % adding two graphs in a same plot
y = (100-t)-((100-t).^2)./100; % Exact solution
plot(t,y);% plotting exact solution
xlabel('t');% labeling x axis
ylabel('y');% labeling y label
legend('Euler','Exact');% adding legend to the plot

Output


Related Solutions

Write a MATLAB script file that will give the value of f(x) using method of least...
Write a MATLAB script file that will give the value of f(x) using method of least squares and asks the user to enter values of x, y, n (curve fit), and x for f(x).
Write a MATLAB script file that will give the value of f(x) using method of least...
Write a MATLAB script file that will give the value of f(x) using method of least squares and asks the user to enter values of x, y, n (linear, quadratic, or cubic), and x for f(x).
Write a MATLAB script file to integrate  using trapezoid method (do not use trapz command for this...
Write a MATLAB script file to integrate  using trapezoid method (do not use trapz command for this part, write your own script). Consider x=-0.5 to 3 with Δt=0.01, and compare your result with using “integral” and "trapz" commands (all in one file).
Solve using PYTHON PROGRAMMING 9. Write a script that reads a file “ai_trends.txt”, into a list...
Solve using PYTHON PROGRAMMING 9. Write a script that reads a file “ai_trends.txt”, into a list of words, eliminates from the list of words the words in the file “stopwords_en.txt” and then a. Calculates the average occurrence of the words. Occurrence is the number of times a word is appearing in the text b. Calculates the longest word c. Calculates the average word length. This is based on the unique words: each word counts as one d. Create a bar...
Solve using PYTHON PROGRAMMING Write a script that reads a file “cars.csv”, into a pandas structure...
Solve using PYTHON PROGRAMMING Write a script that reads a file “cars.csv”, into a pandas structure and then print a. the first 3 rows and the last 3 of the dataset b. the 3 cars with the lowest average-mileage c. the 3 cars with the highest average-mileage. Solve using PYTHON PROGRAMMING
write a Matlab function file to solve system Ax=b by using the output of the function...
write a Matlab function file to solve system Ax=b by using the output of the function lufac2a your function should have inputs f=matrix return from lufac2a, piv=array return by lufac2a and b=right hand side of your system.the only output for your system should be x guideline 1.use the column access for the matrix entries 2. do not create any other matrix in your function-get your data directly from the matrix passed into your function 3.do not use Matlab command designed...
To find a positive root for , write a MATLAB script file that uses Bisection method....
To find a positive root for , write a MATLAB script file that uses Bisection method. Choose any initial value that is needed. Use absolute relative approximate error to be less than 0.01. Your code should report the number of iteration and the value of x.
. Solve the Initial value problem by using Laplace transforms: ? ′′ + 3? ′ +...
. Solve the Initial value problem by using Laplace transforms: ? ′′ + 3? ′ + 2? = 6? −? , ?(0) = 2 ? ′ (0) = 8
Solve using matlab code The initial value problem dydx−y= 2 cosx, y(0) =−2 has the exact...
Solve using matlab code The initial value problem dydx−y= 2 cosx, y(0) =−2 has the exact solution y(x) =−e^x −√2 cos (x+π4). Use the Euler method to solve the initial value problem for 0≤x≤2 using n=10,50,100,200 and plot solutions in one graph. Repeat #1 using the Runge-Kutta method and plot solutions in one graph with the exact solution
Write a MATLAB script or function that returns the required initial velocity of the ping pong...
Write a MATLAB script or function that returns the required initial velocity of the ping pong ball required to launch it a specified distance. Use projectile motion equations. Keep in mind that the initial firing height will change depending on the proposed catapult design. Primary considerations in the catapult design are accuracy and repeatability as groups will be tasked with hitting the target (cup) repeatedly at distances ranging from 7 to 9 ft. (cup moved in 6 in. increments).
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT