Problem on solving with dsolve
Mostra commenti meno recenti
I'm having trouble using dsolve to solve a DE using 2 strategies. I'm getting different answers. Please advise. NOte: warning doesn't botter me.
% FILE: test.m
% Solving an ODE (RLC circuit response) with innitial conditions. Example 2.29 from Kalechman
% Pratical Matlab applications for engineers pag 196
% equation: (1/36)*D2y+(1/9)*Dy+(1/9)*y=0
% initial conditions: y(0) = 0 and Dy(0)= 432
% solution: 432*t*exp(-2*t)
% 2 differente strategies using dsolve with explot or fplot;
clear; sym eq;
% strategy #1 - works fine but with warning
% using a single string and call dsolve
% solution (correct, OK): 432*t*exp(-2*t)
% model = dsolve('(1/36)*D2y+(1/9)*Dy+(1/9)*y=0','y(0) = 0','Dy(0)= 432','t')
% strategy #2 - works, different answer and includes warning
% build equation in one outside string and call dsolve
% eq=strcat('1/36','*D2y+','1/9','*Dy+','1/9','=0')
% eq = '1/36' + '*D2y+' + '1/9' + '*Dy+' + '1/9' + '=0' % gives error
eq='1/36*D2y+1/9*Dy+1/9=0'; % solution (wrong, NOK): 433/4 - (433*exp(-4*t))/4 - t
model=dsolve(eq,'y(0) = 0','Dy(0)= 432','t')
% plotting
figure(1)
% ezplot(model); % or
fplot(model);
xlabel('t(s)')
ylabel('v(volts)')
title('v(t) vs t')
axis([0 6 0 90]);
Risposte (1)
You got the wrong result because your equation is wrong, you forgot to include '*y' in the 3rd approach.
eq=strcat('1/36','*D2y+','1/9','*Dy+','1/9','*y','=0')
model=dsolve(eq,'y(0) = 0','Dy(0)= 432','t')
And as the warning suggest, it is best to use sym objects rather than char vectors and strings.
Categorie
Scopri di più su Symbolic Math Toolbox in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
