Matlab - Numerical Analysis

In summary: Also, the function f is not defined correctly.In summary, the conversation is about the differential equation for the velocity of an object falling near Earth's surface with air resistance proportional to velocity squared. The parameters g, m, and c are given and the task is to plot the exact solution and numerical solution using the 4th order predictor-corrector Runge-Kutta method. The code provided has some errors and is incomplete.
  • #1
Mech-Master
13
0

Homework Statement



An object of mass m falls from rest at a point near the Earth's surface. If the air resistance is proportional to the velocity v^2, the differential equation for the velocity as a function of time is given by m*dv/dt = mg - cv^2

For the given paraments g = 9.81 m/s^2. m = 68.1 kg and c = 1.5 kg/m. plot the exact solution and the numerical solution v(t) obtained from the 4th order predictor-corrector runge kutta methods using an interval of dt = 0.25 seconds in the domain of 0<t<6

(I need help with the code of runga kutta, I am horrible at matlab


Homework Equations



m*dv/dt = mg - cv^2


The Attempt at a Solution





clear
clc
g = 9.81
m = 68.1
c = 1.5
tmax = 6
dt = 0.25
t = [0:dt:tmax]
v(1) =1;

%Exact Solution
vs = sqrt(m*g/c)*tanh(t*sqrt(g*c/m));
plot(t,vs,'s'), hold on

%Runge-Kutta
for i = 1:length(t)-1
f= g - c*v(i).^2/m;
k1= f(v(i));
k2= f(t(i)+(dt/2), v(i) + (dt/2)*k1);
k3 =f(t(i)+(dt/2), v(i) + (dt/2)*k2);
k4 =f(t(i)+ dt, + v(i) + dt*k3);
v(i+1) = v(i) + (dt/6)*(k1+2*k2+2*k3+k4);
end
 
Physics news on Phys.org
  • #2
If you look in the first row of the for loop, the vector v is not defined so the code dosen't make sense.
 

1. What is Matlab and how is it used in numerical analysis?

Matlab is a high-level programming language and interactive environment that is commonly used in scientific and engineering applications, including numerical analysis. It provides a wide range of tools and functions for performing numerical computations, such as solving equations, interpolating data, and performing matrix operations.

2. What are the advantages of using Matlab for numerical analysis?

One of the main advantages of using Matlab for numerical analysis is its efficiency and speed in performing complex calculations. It also has a user-friendly interface that makes it easy to visualize and manipulate data. Additionally, Matlab has a large library of built-in functions and toolboxes specifically designed for numerical analysis, which can save time and effort in coding.

3. Can Matlab handle large datasets in numerical analysis?

Yes, Matlab has the capability to handle large datasets in numerical analysis. It uses efficient algorithms and memory management techniques to handle large amounts of data. Additionally, it has options for parallel computing, which can further speed up the analysis of large datasets.

4. How accurate are the results obtained from numerical analysis in Matlab?

The accuracy of the results obtained from numerical analysis in Matlab depends on the precision of the input data and the chosen numerical methods. However, Matlab has high-precision arithmetic and supports various numerical methods, allowing for accurate results to be obtained.

5. Can Matlab be used for both linear and non-linear numerical analysis?

Yes, Matlab can be used for both linear and non-linear numerical analysis. It has built-in functions and toolboxes for solving linear systems of equations, as well as for solving non-linear equations using methods such as Newton's method and the Broyden-Fletcher-Goldfarb-Shanno (BFGS) method.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
4
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
6
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
6
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
941
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Programming and Computer Science
Replies
15
Views
2K
Replies
5
Views
361
  • Engineering and Comp Sci Homework Help
Replies
3
Views
1K
Back
Top