how to plot solution of ODE eqution with out using fplot ?
10 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
hi I want to solve a simple differential equation . I solved the equation and plotted the answer . How ever I ploted the answer using fplot .I want to plot using the command 'plot' or 'stem' , my question is it possible to convert V_Sol to double ? I tried typing double(V_Sol) but I get this error :
Error using symengine
Unable to convert expression containing symbolic variables into double array. Apply 'subs' function first to substitute values
for variables.
here is my code
% this code is used to show how to use ode in matlab, via a simple problem
% for serios RC circuit with DC supply
clc;clear al;clc;
syms V_c(t)
R=1e3; % value of R
C=1e-3; % value of C
U=5; % value of the DC supply
ode = diff(V_c)+(1/(R*C) )*V_c == (1/(R*C) )*U; % the kirhov voltage law in the RC circuit
cond = V_c(0) == 0; % intial condtions
V_Sol(t) = dsolve(ode,cond); %solve V_c(t)
fplot(V_Sol(t),[0,5]);% plot V_c(t)
xlabel('t[sec]');
ylabel('V_c(t)[v]');
title(' solution of : $\frac{dV_c(t)}{dt}*RC +V_c(t)=U $','Interpreter','latex','FontSize', 14);
grid on;
legend('V_c(t)');
% plot V_Sol using plot command
t=0:0.001:5;
subs t;
plot(t,double(V_Sol))
0 commentaires
Réponse acceptée
VBBV
le 8 Mai 2022
% this code is used to show how to use ode in matlab, via a simple problem
% for serios RC circuit with DC supply
clc;clear al;clc;
syms V_c(t)
R=1e3; % value of R
C=1e-3; % value of C
U=5; % value of the DC supply
ode = diff(V_c)+(1/(R*C) )*V_c == (1/(R*C) )*U; % the kirhov voltage law in the RC circuit
cond = V_c(0) == 0; % intial condtions
V_Sol(t) = dsolve(ode,cond) %solve V_c(t)
fplot(V_Sol(t),[0,5]);% plot V_c(t)
xlabel('t[sec]');
ylabel('V_c(t)[v]');
title(' solution of : $\frac{dV_c(t)}{dt}*RC +V_c(t)=U $','Interpreter','latex','FontSize', 14);
grid on;
legend('V_c(t)');
% plot V_Sol using plot command
T = 0:0.001:5;
%subs t;
plot(T,subs(V_Sol,t,0:0.001:5)) % dont use same variable for plotting, since t is symbolic
2 commentaires
VBBV
le 8 Mai 2022
% this code is used to show how to use ode in matlab, via a simple problem
% for serios RC circuit with DC supply
clc;clear al;clc;
syms V_c(t)
R=1e3; % value of R
C=1e-3; % value of C
U=5; % value of the DC supply
ode = diff(V_c)+(1/(R*C) )*V_c == (1/(R*C) )*U; % the kirhov voltage law in the RC circuit
cond = V_c(0) == 0; % intial condtions
V_Sol(t) = dsolve(ode,cond); %solve V_c(t)
fplot(V_Sol(t),[0,5]);% plot V_c(t)
xlabel('t[sec]');
ylabel('V_c(t)[v]');
title(' solution of : $\frac{dV_c(t)}{dt}*RC +V_c(t)=U $','Interpreter','latex','FontSize', 14);
grid on;
legend('V_c(t)');
% plot V_Sol using plot command
Vsol = matlabFunction(V_Sol);
t = 0:0.001:5;
plot(t,Vsol(t))
Voir également
Catégories
En savoir plus sur Calculus dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



