Write an m-file that 1. Plots f(t) over the interval o st 2 usithe equation 6)-1
ID: 2248451 • Letter: W
Question
Write an m-file that 1. Plots f(t) over the interval o st 2 usithe equation 6)-1/2 ts ee 2. Write a MATLAB fumction find fN that determines f() gven an integer value of n and the time vector from part (1). The syntax for the calling the function must be fn = find.fa(t,N): Realize the function using a For-Loop 3. Using the MATLAB function find.IN, determine vectors representing fi(t), Jio(t), and fioo(t), and plot these functions in the figure containing flt) using a dotted, dash-dotted, and solid curve, respectively. Use a legend to distinguish the four curves in the figure, and appropriately label the axes and title the plot.Explanation / Answer
answer to 1:
clc
clear all
t=0:1/10000:2; %% the time axis is divided into 10000 equally spaced points
F_t=t./2; %% F is calculated for each point
%% curve is plotted between F and t
hold on
title('Plot of F(t)=t/2 versus time') %% title for the graph
xlabel('time');%% x axis labeling
ylabel('F(t)=t/2');%% y axis labeling
plot (t,F_t,'k--') %% k=black -- for dashed line and the plot command
solution to 2:
function x= find_fn(t,N) %% function definition
row=1;
%% a column matrix is formed here containing the elements of the func at each time step
for time_vect=0:1/t:2
func(row,:)=time_vect./2;
row=row+1;
end
%% the value at Nth time step is returned
x=func(N,:);
solution to 3:
clc
clear all
t=0:1/10000:2; %% the time axis is divided into 10000 equally spaced points
F_t=t./2; %% F is calculated for each point
% curve is plotted between F and t
title('Plot of F(t)=t/2 versus time') %% title for the graph
xlabel('time');%% x axis labeling
ylabel('F(t)=t/2');%% y axis labeling
axis ([0 2 0 2])
hold on
plot (t,F_t,'k--') %% k=black -- for dashed line and the plot command
% these points are selected because if we divide 0-2 by 10000 points and
% want to plot that point on a scale of 1 then that value is too small to
% be visible that is why these points are taken
N1=2500/10000; %2500 point
N10=5000/10000; %5000 point
N100=10000/10000; %10000 point
% plot a curve between two point (x1,y1) and (x2,y2) as plot([x1 x2],[y1 y2])
plot([N1 N1],[0 F_t(2500)],'b:')
plot([N10 N10],[0 F_t(5000)],'g-.')
plot([N100 N100],[0 F_t(10000)],'m-')
hold off
legend('main plot','N2500','N5000','N10000')
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.