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]);

답변 (1개)

Dyuman Joshi
Dyuman Joshi 2023년 4월 8일

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')
eq = '1/36*D2y+1/9*Dy+1/9*y=0'
model=dsolve(eq,'y(0) = 0','Dy(0)= 432','t')
Warning: Support of character vectors and strings will be removed in a future release. Use sym objects to define differential equations instead.
model = 
And as the warning suggest, it is best to use sym objects rather than char vectors and strings.

카테고리

도움말 센터File Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

제품

릴리스

R2020a

질문:

2023년 4월 8일

답변:

2023년 4월 8일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by