Write a MATLAB function to solve the generic 2nd order, linear, constant coeffic
ID: 3603955 • Letter: W
Question
Write a MATLAB function to solve the generic 2nd order, linear, constant coefficient, non-homogeneous, differential equation: d2x dx a + b + cx = F(t) Where a, b, and c are all constants and F(t) is a function of time. Your MATLAB script should use the ode45 solver to determine the solution. The first line of the functiorn should be function [tyl = hw4-lastname(a,b,c,ty_at-end) where: . a, b, c: constant coefficients in differential equation f: handle to the function Fit) · VLO: 2-element vector containing the initial conditions . tend: final time for solution Once your function is working, run it for the initial value problem: mi + 5x = 10 cos(3t); i(0) = x(0) = 0 Have your script plot both the solution x(t) and the forcing function F(t) on the same graph.Explanation / Answer
For example, let us compute the derivative of the function f(t) = 3t2 + 2t-2
SCRIPT EXAMPLE: Create a script file and type the following code into it -
syms t
f = 3*t^2 + 2*t^(-2);
diff(f)
When the above code is compiled and executed, it produces the following result -
ans =6*t - 4/t^3
Following is Octave equivalent of the above calculation -
pkg load symbolic
symbols
t = sym("t");
f = 3*t^2 + 2*t^(-2);
differentiate(f,t)
Octave executes the code and returns the following result -
ans = -(4.0)*t^(-3.0)+(6.0)*t
Verification of Elementary Rules of Differentiation
Let us briefly state various equations or rules for differentiation of functions and verify these rules. For this purpose, we will write f'(x) for a first order derivative and f"(x) for a second order derivative.
Following are the rules for differentiation -
Rule 1
For any functions f and g and any real numbers a and b are the derivative of the function:
h(x) = af(x) + bg(x) with respect to x is given by -
h'(x) = af'(x) + bg'(x)
Rule 2
The sum and subtraction rules state that if f and g are two functions, f' and g' are their derivatives respectively, then,
(f + g)' = f' + g'
(f - g)' = f' - g'
Rule 3
The product rule states that if f and g are two functions, f' and g' are their derivatives respectively, then,
(f.g)' = f'.g + g'.f
Rule 4
The quotient rule states that if f and g are two functions, f' and g' are their derivatives respectively, then,
(f/g)' = (f'.g - g'.f)/g2
Rule 5
The polynomial or elementary power rule states that, if y = f(x) = xn, then f' = n. x(n-1)
A direct outcome of this rule is that the derivative of any constant is zero, i.e., if y = k, any constant, then
f' = 0
Rule 6
The chain rule states that, derivative of the function of a function h(x) = f(g(x)) with respect to x is,
h'(x)= f'(g(x)).g'(x)
Example
Create a script file and type the following code into it -
syms x
syms t
f = (x + 2)*(x^2 + 3)
der1 = diff(f)
f = (t^2 + 3)*(sqrt(t) + t^3)
der2 = diff(f)
f = (x^2 - 2*x + 1)*(3*x^3 - 5*x^2 + 2)
der3 = diff(f)
f = (2*x^2 + 3*x)/(x^3 + 1)
der4 = diff(f)
f = (x^2 + 1)^17
der5 = diff(f)
f = (t^3 + 3* t^2 + 5*t -9)^(-6)
der6 = diff(f)
When you run the file, MATLAB displays the following result -
f = (x^2 + 3)*(x + 2)
der1 = 2*x*(x + 2) + x^2 + 3
f = (t^(1/2) + t^3)*(t^2 + 3)
der2 = (t^2 + 3)*(3*t^2 + 1/(2*t^(1/2))) + 2*t*(t^(1/2) + t^3)
f = (x^2 - 2*x + 1)*(3*x^3 - 5*x^2 + 2)
der3 = (2*x - 2)*(3*x^3 - 5*x^2 + 2) - (- 9*x^2 + 10*x)*(x^2 - 2*x + 1
f = (2*x^2 + 3*x)/(x^3 + 1)
der4 =(4*x + 3)/(x^3 + 1) - (3*x^2*(2*x^2 + 3*x))/(x^3 + 1)^2
f =(x^2 + 1)^17
der5 = 34*x*(x^2 + 1)^16
f =1/(t^3 + 3*t^2 + 5*t - 9)^6
der6 = -(6*(3*t^2 + 6*t + 5))/(t^3 + 3*t^2 + 5*t - 9)^7
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.