HELP: looping a function and plot (ode23)
Show older comments
Hi, so the question for my exercise is : Write a MATLAB code to solve the differential equation for 𝑣𝑜𝑢𝑡 using function ode23() and plot the output. hint: to get the output waveform, plot(t, y(:,1))
The graph output was in subplot i believe. and the equation of each graph are the same except for the value of R. I tried doing the code with my little matlab knowledge and after searching the mathwork, i've tried to mix and match some coding that i think were relevent and make sense for my question. Here is my code;
script:
function ode23()
function myout=fun(t,y,R)
Vi=5; C=0.1; L=0.1;
if nargin < 0.5 || isempty(R) %i dont really know about this one
R = 0.5; % Your default value
end
myout=[(Vi-R*C*y(2)-y(1))/(L*C)];
end
end
command windows:
tspan=[0, 10]; ohm='x03A9';
y0=[0];
[t_r1, y_r1]=ode23(@(t,y) fun(t,y,0.5), tspan, y0);
plot(t_r1, y_r1(:,1))
[t_r2, y_r2]=ode23(@(t,y) fun(t,y,2), tspan, y0);
plot(t_r2, y_r2(:,1))
[t_r3, y_r3]=ode23(@(t,y) fun(t,y,4), tspan, y0);
plot(t_r2, y_r2(:,1))
subplot(3,1,1)
plot(t_r1, y_r1(:,1))
ylabel('Vout'), xlabel('Time(s)')
title('Underdamped response of R=0.5''ohm')
subplot(3,1,2)
plot(t_r2, y_r2(:,1))
ylabel('Vout'), xlabel('Time(s)')
title('Critically damped response of R=2''ohm')
subplot(3,1,3)
plot(t_r3, y_r3(:,1))
ylabel('Vout'), xlabel('Time(s)')
title('Over damped response of R=0.5''ohm')
If anyone can help me, that would be great. Thanks in advance.
Accepted Answer
More Answers (0)
Categories
Find more on Programming 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!