(1) , (2), (3)
-----------------------------------sin_t.m----------------------------------
% calculate and return the value of sin(t)
% n is the number of terms in the series
function [val] = sin_t(t , n)
val = 0;
for i = 1 : n
% calculate the i th term and add to val
val = val + ( ( (-1) ^ ( i - 1 ) ) * ( t ^ ( 2 * i - 1 ) ) / factorial( 2 * i - 1 ) );
end
end
---------------------main.m---------------------
% create a vector for time
t = [ -2 * pi : 0.01 : 2 * pi ];
% create a vector for same length as t to store the corresponding values of
% sin(t)
y = [ 1 : length(t) ];
for i = 1 : length(t)
y(i) = sin_t( t(i) , 10 );
end
% set the label of axis
xlabel('t');
ylabel('sin(t)');
grid on
hold
% plot the graph
plot(t , y);
Sample Output
(4)
------------------------sin_t.m-----------------------
% calculate and return the value of sin(t)
% n is the number of terms in the series
function [val] = sin_t(t , n)
% calculate the sum of n = 1 to 7
val = ( ( t ^ ( 1 ) ) / factorial( 1 ) ) - ( ( t ^ ( 3 ) ) / factorial( 3 ) ) + ( ( t ^ ( 5 ) ) / factorial( 5 ) ) - ( ( t ^ ( 7 ) ) /factorial( 7 ) ) + ( ( t ^ ( 9 ) ) / factorial( 9 ) ) - ( ( t ^ ( 11 ) ) / factorial( 11 ) ) + ( ( t ^ ( 13 ) ) / factorial( 13 ) );
end
-------------------------main.m-------------------------
% create a vector for time
t = [ -2 * pi : 0.01 : 2 * pi ];
% create a vector for same length as t to store the corresponding values of
% sin(t)
y = [ 1 : length(t) ];
n = 13;
for i = 1 : length(t)
y(i) = sin_t( t(i) );
end
% set the label of axis
xlabel('t');
ylabel('sin(t)');
grid on
hold
% plot the graph
plot(t , y);
Sample Output
(5)
-----------------------------------sin_t.m----------------------------------
% calculate and return the value of sin(t)
% n is the number of terms in the series
function [val] = sin_t(t , n)
val = 0;
for i = 1 : n
% calculate the i th term and add to val
val = val + ( ( (-1) ^ ( i - 1 ) ) * ( t ^ ( 2 * i - 1 ) ) / factorial( 2 * i - 1 ) );
end
end
---------------------main.m--------------------
% create a vector for time
t = [ -2 * pi : 0.01 : 2 * pi ];
% create a vector for same length as t to store the corresponding values of
% sin(t)
y = [ 1 : length(t) ];
n = 13;
for i = 1 : length(t)
y(i) = sin_t( t(i) , n );
end
% set the label of axis
xlabel('t');
ylabel('sin(t)');
grid on
hold
% plot the graph
plot(t , y);
Sample Output
Image 1 is the template that may help to solve this problem and it will serve...
I need help in MATLAB. I'm working on a circuits lab report and I want to plot the derivative of an input signal. The circuit is a differentiator OpAmp. It is receiving a triangle wave as an input and should output a square wave. (I've included my existing code.) The output formula is: Vout = -(Rf)*C*(dVin/dt) Where Rf is feedback resistance: Rf = 1*10^6; and C = 1*10^-6. EXISTING CODE: %% This section is copied, and then modified from another...
(15 points) This problem is related to Problem 3.7 in the text. consider reviewing Section 3.2.1.1. The following MATLAB program plots the function v(t) = 5 cos(300 - 24t) + 2 sin (600 - 2x + ) t = 0: step :Tmax; V = 5* cos(2pi"300"t) + 2 sin(2"pi*600*t + pi/2); plot(t,v) xlabel('time (seconds)') ylabel('signal v(t)) axis([xmin,xmax,ymin,ymax]) What is the period of the signal v(t)? Suppose that we want to produce a plot that covers exactly 4 periods and has...
Project in matlab. I have the correct ak value but not the
correct ao value. My code is attached below also
2. Determine and plot the magnitude and phase spectrum of the Fourier series coefficients a, that is, plot ja, I as a function of discrete frequencies Jok and La, as a function of discrete frequencies fok 03 025 蓋0.2 0.15 0.1 o o5 ·10-8-6 4610 phase -2 -2 8- t= 0: .01:4; 9- to = 4; 10- fo =1/4;...
How can I get my while loop to run until my condition in my if statement is met? (In MATLAB) clc%clears screen clear all%clears history close all%closes all files format long %Euler's Method %Initial conditions and setup %Projectile motion x=3;%randi(3); y=3;%randi(3); figure('color','white'); plot(x,y,'bo'); hold on wind = (-10 + 20*rand(1)); fprintf('The wind speed is %2.2i\n',wind); v0= input('Initial velocity(m/s): '); a= input('Angle of projection(in degrees): '); a=a*pi/180; h=.01; cd=.1; %cdy=.1; %cdx=(rand*2-1)/2; %cdy=(rand*2-1)/2; m=1.5; g=9.8; %acceleration due to gravity in m/s^2 %td=2*v0*sin(a)/g;...
modify this code is ready
% Use ODE45 to solve Example 4.4.3, page 205, Palm 3rd
edition
% Spring Mass Damper system with initial displacement
function SolveODEs()
clf %clear any existing plots
% Time range Initial Conditions
[t,y] = ode45( @deriv, [0,2], [1,0] );
% tvals yvals color and style
plot( t, y(:,1), 'blue');
title('Spring Mass Damper with initial displacement');
xlabel('Time - s');
ylabel('Position - ft');
pause % hit enter to go to the next plot
plot( t, y(:,2), 'blue--');...
I'm trying to solve this differential equations by using
matlab. But I don't know the reason why I can't get the solutions.
I've attached matlab code and few differential equation. Please
find a the way to solve this problem.
second oder ode2.m x+ function, second-oder-ode2 t-0:0.001:30 initial-x = 0; initial-dxdt = 0: lt.影=ode45( @rhs, t, [initial.x initial.dxdt ] ); plot(t.(:,1l): xlabel( t); ylabel(x): 申 function dxdt=rhs( t, x) dxdt-1 =x(2); dxdt-2 (-50 x(2)+61.25+((1-cos(4 pi 10 t))/2) (47380 x(1)-3-7428 x(1) 2...
I'm
trying to solve this problem by using matlab. But I don't know
reason why I can't get the solutions. I wanna get a plot of this
differential equation. Please find a way how to solve this problem.
May there're errors in the code. Please check it.
second-oder-ode2.m x 曱function, second-oder-ode2 t=0:0.001 :30; initial-× = 0; in i t i al-dxdt 0; lt,影=ode45( @rhs, t. [initial.x initial-dxdt ] ); plot( (:, 1) ) ; xlabel( 't); ylabel(): function dxdt=rhs( t,...
Hello, i have this matlab code where i have to track a red ball from and uploaded video, and plot its direction in x-y direction My Question is how can i add x vs time plot and y vs time plot in this code. Thank you if exist('V','var') delete(V); end clear;clc; V=VideoReader('video.mp4'); figure(1); x=[];y=[]; i=1; while hasFrame(V) J=readFrame(V); figure(1);imshow(J);title(['Frame No. ',num2str(i)]); if (i>=28 && i<=132) bw=J(:,:,1)>200 & J(:,:,2)<80 & J(:,:,3)<80; bw=imfill(bw,'holes'); A=regionprops(bw,'Centroid'); x(end+1)=A.Centroid(1); y(end+1)=A.Centroid(2); hold on; plot(x,y,'*k');hold off; end i=i+1;...
Amplitude=3; fs=8000; n=0:399; t=0:1/fs: n*1/fs-1/fs; signal=3+3*cos(2*pi*1100*t)+3*cos(2*pi*2200*t)+3*cos(2*pi*3300*t); fftSignal= fft(signal); fftSignal=f ftshift (fftSignal); f=fs/2*linspace(-1,1,fs); plot(f,abs(fftsignal); xlabel('Frequency(Hz)’) ylabel('amplitude(v)') title('Spectral domain') plz code above using For ..End loop to archive the same results.
8. The Maclaurin series (a special case of the Taylor series that is discussed later in this class) allows us to express a differentiable, analytic function as an infinite degree polynomial. Here is the degree seven polynomial approximation of the sine: x3 x5 x? 3! 5! 7! + Use Matlab to generate a plot of sin(x) (solid blue line) and its polynomial approximation (dashed red line) for x = 0 to 31/2 and y from -1.5 to 2. Use the...