Clear Filters
Clear Filters

Using the piecewise function and integration function with fplot

2 views (last 30 days)
How do I graph the three integral functions (V1,V2, &V3) below? I want to set the plot range for each of the three functions
%set up capacitor graph
V1 = (1/0.3e-9)*int(t*(5000/3),t); %Plot 0<t<3
Unrecognized function or variable 't'.
V2 = (1/0.3e-9)*int(5e-3,t); %Plot 3<t<6
V3 = (1/0.3e-9)*int(-5000*t+35e-3,t); %Plot 6<t<7
cap_volt = [V1 V2 V3];
fplot(cap_volt,[0 7])
%fplot(capacitor_voltage_values,[0 7]) %fplot defaults to [-5 5] so need to change range
%xlim([0 7]) %set the x-axis to 7
%ylim([-80 30])
title('capacitor voltage')
subtitle('V_L(t = 6.5\mus) = -75V')
xlabel('time (\mus)') %\mu adds the micro symbol to the x-axis label
ylabel('voltage (V)')
grid on

Answers (2)

Walter Roberson
Walter Roberson on 31 Dec 2023
syms t
%set up capacitor graph
V1 = (1/0.3e-9)*int(t*(5000/3),t); %Plot 0<t<3
V2 = (1/0.3e-9)*int(5e-3,t); %Plot 3<t<6
V3 = (1/0.3e-9)*int(-5000*t+35e-3,t); %Plot 6<t<7
cap_volt = [V1 V2 V3];
fplot(cap_volt,[0 7])
%fplot(capacitor_voltage_values,[0 7]) %fplot defaults to [-5 5] so need to change range
%xlim([0 7]) %set the x-axis to 7
%ylim([-80 30])
title('capacitor voltage')
subtitle('V_L(t = 6.5\mus) = -75V')
xlabel('time (\mus)') %\mu adds the micro symbol to the x-axis label
ylabel('voltage (V)')
grid on
  1 Comment
madhan ravi
madhan ravi on 1 Jan 2024
Looks like the OP forgot to copy paste the syms t. As the plot produced by your code is already posted by the OP.

Sign in to comment.


Voss
Voss on 31 Dec 2023
syms t
%set up capacitor graph
V1 = (1/0.3e-9)*int(t*(5000/3),t); %Plot 0<t<3
V2 = (1/0.3e-9)*int(5e-3,t); %Plot 3<t<6
V3 = (1/0.3e-9)*int(-5000*t+35e-3,t); %Plot 6<t<7
cap_volt = piecewise(0<t & t<3, V1, 3<t & t<6, V2, 6<t & t<7, V3);
fplot(cap_volt,[0 7])
%fplot(capacitor_voltage_values,[0 7]) %fplot defaults to [-5 5] so need to change range
%xlim([0 7]) %set the x-axis to 7
%ylim([-80 30])
title('capacitor voltage')
subtitle('V_L(t = 6.5\mus) = -75V')
xlabel('time (\mus)') %\mu adds the micro symbol to the x-axis label
ylabel('voltage (V)')
grid on

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!