I cannot get fplot to plot my piecewise function past an x-axis value of 5
조회 수: 4 (최근 30일)
이전 댓글 표시
Here is my code. The axis goes to 7 but the data does not go beyond 5.
syms t %declare a symbol
voltage_values = piecewise(0<=t<=3,25,3<=t<=6,0,6<=t<=7,-75);
fplot(t,voltage_values)
xlim([0 7]) %set the x-axis to 7
title('Inductor voltage')
xlabel('time (\mus)') %\mu adds the micro symbol to the x-axis label
ylabel('voltage (V)')
grid on
댓글 수: 0
채택된 답변
Torsten
2023년 12월 31일
syms t %declare a symbol
voltage_values = piecewise(0<=t<=3,25,3<t<=6,0,6<t<=7,-75);
fplot(t,voltage_values,[0 7])
%xlim([0 7]) %set the x-axis to 7
title('Inductor voltage')
xlabel('time (\mus)') %\mu adds the micro symbol to the x-axis label
ylabel('voltage (V)')
grid on
추가 답변 (2개)
Star Strider
2023년 12월 31일
The default independent variable limits for fplot are (-5,5). If you want a larger or different independent variable value, tell it using the second argument.
Try this —
syms t %declare a symbol
voltage_values = piecewise(0<=t<=3,25,3<=t<=6,0,6<=t<=7,-75);
figure
fplot(voltage_values, [0 7])
xlim([0 7]) %set the x-axis to 7
title('Inductor voltage')
xlabel('time (\mus)') %\mu adds the micro symbol to the x-axis label
ylabel('voltage (V)')
grid on
.
댓글 수: 0
Hassaan
2023년 12월 31일
편집: Hassaan
2023년 12월 31일
I will assume that the piecewise function should actually have three conditions: up to 3, between 3 and 5, and then from 5 to 7. Here's how you could write it.
syms t % Declare a symbol
% Define the voltage_values as a piecewise function
voltage_values = piecewise(0<=t<3, 25, 3<=t<5, 0, 5<=t<=7, -75);
% Plot the function
fplot(t, voltage_values, [0, 7]); % Set the range of t from 0 to 7
% Set the title and labels with proper units
title('Inductor voltage');
xlabel('time (\mus)'); % \mu adds the micro symbol to the x-axis label
ylabel('Voltage (V)');
grid on
With the range [0, 7] provided to fplot, it will plot the function across the entire x-axis range you've specified. The piecewise function is corrected to reflect three ranges, which should now correctly show values up to t = 7. Ensure that the range of t you plot (using fplot) and the conditions in the piecewise function match to display the data correctly.
------------------------------------------------------------------------------------------------------------------------------------------------
If you find the solution helpful and it resolves your issue, it would be greatly appreciated if you could accept the answer. Also, leaving an upvote and a comment are also wonderful ways to provide feedback.
Professional Interests
- Technical Services and Consulting
- Embedded Systems
- Electrical and Electronics Engineering
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Assumptions에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!