Filter löschen
Filter löschen

Using the piecewise function and integration function with fplot

2 Ansichten (letzte 30 Tage)
David Cole
David Cole am 31 Dez. 2023
Kommentiert: madhan ravi am 1 Jan. 2024
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

Antworten (2)

Walter Roberson
Walter Roberson am 31 Dez. 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 Kommentar
madhan ravi
madhan ravi am 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.

Melden Sie sich an, um zu kommentieren.


Voss
Voss am 31 Dez. 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
  2 Kommentare
Torsten
Torsten am 1 Jan. 2024
Better define cap_volt also for t=0, t=3, t=6 and t=7.
Voss
Voss am 1 Jan. 2024
I agree, but I'm doing what OP said he wanted.

Melden Sie sich an, um zu kommentieren.

Produkte


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by