how to plot solution of ODE eqution with out using fplot ?
4 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
VBBV
on 8 May 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
See Also
Categories
Find more on Graphics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!