How can i include repeating and complex roots within my code ?
Mostrar comentarios más antiguos
Displayed below is a set code that is meant to solve linear second order homogeneous differential equations where the user is prompted to include 3 coefficients and two intial conditions. I have been tasked to "complete" this code by allowing the roots to be complex and repeated as solutions generated originate from 2 real distinct roots. Any support into how i can alter this code to fit these requirements are greatly appreciated.
c1='Please enter a value for coefficient 1 ';
a=input(c1);
c2='Please enter a value for coefficient 2 ';
b=input(c2);
c3='Please enter a value for coefficient 3 ';
c=input(c3);
intial1='Enter initial condition for the solution' ;
ytime0=input(intial1);
intial2='Enter initial condition of the derivative of solution' ;
ydtime0=input(intial2);
fprintf('The values entered: \n a = %d \n b = %d \n c = %d\n', a,b,c);
response=(b.^2)-(4*a*c);
disp(response)
if(response>0)
clc();
disp('The response is over-damped')
m1=(-b+sqrt(response))./(2*a);
m2=(-b-sqrt(response))./(2*a);
fprintf(' The roots of the characteristic equation \n m1 = %d \n m2 = %d \n', m1, m2);
D=[1 1;m1 m2];
F=[ytime0;ydtime0];
sol=inv(D)*F;
cons1=sol(1);
cons2=sol(2);
if (m1>m2)
tau=1/m1;
fprintf('the value is %d\n',tau)
end
if (m1<m2)
tau=1/m2;
fprintf('the value is %d\n',tau)
end
time5=7*abs(tau);
disp(time5)
t=linspace(0,time5);
y=cons1*exp(m1*t)+cons2*exp(m2*t);
plot(t,y)
end
if(response==0)
disp('The response is critically-damped')
end
if(response<0)
disp('The response is underdamped')
end
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Numerical Integration and Differential Equations en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!