Question

MATLAB question:

Task 4 Many real world objects travel in a jagged manner that is best represented by piecewise functions. For example, the veTask 5 Recall that the following Taylor series is used to approximate Cosine: cos(x)- (2n) You have been tasked with developi

Task 4 Many real world objects travel in a jagged manner that is best represented by piecewise functions. For example, the velocity of a rocket may change sharply when thrusters are enabled or disabled and due to various external factors. The velocity of a rocket can be modelled by v(t) where t represents the time 112-5t 0sts10 1100-5t10StS20 vt) 502( 20)25 20sIs 30 1520e0-30) 0 t >30 otherwise Write a function that takes a start and end time as inputs and returns the vectors v and t. The vector t should contain values between start_t and end t at 0.01 increments. The vector v should contain v(t) for each value in t. function [t, v VPiecewise(start_t, end _t) Use the function in an m-file to plot the velocities for t--5 to 80. Hint: Use if statements to break up the different profile conditions.
Task 5 Recall that the following Taylor series is used to approximate Cosine: cos(x)- (2n) You have been tasked with developing an M-file that allows other engineers to quickly determine the minimum n needed to reduce the truncation error below an error threshold. The truncation error is the absolute error between the approximation and MATLAB's cos) function. Note: You may want to Google the Taylor series to gain a better understanding of it. Your code should do the following: Ask the user to enter an error threshold value (it should work with vectors) Find the number of terms (minimum n) needed so that the truncation error is below the user error threshold for x--2π to 2 Print the minimum n value, the mean truncation error and the maximum truncation error using fprintf. Plot the truncation error against x. 1. 2. 3. 4. Test your code with the following error thresholds: 0.1, 0.01, 1e-10. The answers for the thresholds above should be n-8, 9, 16, respectively. This is a reference to see whether your code is working correctly. Hint: Your code may include both while and for loops and/or a created function to calculate the approximation of Cosine.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

TASK 4:

Programming code in MATLAB;

clc;

clear all;

close all;

function [t, v] = VPiecewise(start_t, end_t)
////////////// Creates two vectors v and t
  
//////////// Creating vector t at increments of 0.01
t = start_t:0.01:end_t;
  
///////////// Initializing vector v
v = [];
  
/////////// Using loop to find v values
for i=1:length(t)
  
/////////  Finding profile conditions
if t(i)>=0 && t(i)<=10
//////////// Updaitng vector
v = [v ((11*t(i)*t(i)) - (5*t(i)))];
elseif t(i)>10 && t(i)<=20
///////////// Updaitng vector
v = [v (1100 - (5*t(i)))];
elseif t(i)>20 && t(i)<=30
////////////////// Updaitng vector
v = [v ((50*t(i)) + ( 2 * ( (t(i)-20) ^ (2.5) )))];
elseif t(i)>30
/////////////// Updaitng vector
v = [v ((1520) * ( exp((-0.1)*(t(i)-30)) ))];
else
v = [v 0];
end % If end
  
end % For loop end
  
end % Function end

Script:

//////////// Plotting travel of a real world objects in a jagged manner
[t, v] = VPiecewise(-5, 80);

///////////// Plotting graph
plot(t, v);
title("Travel of a real world objects in a jagged manner");
xlabel("t");
ylabel("v");

MATLAB O/P:

Thavel of areal voild objedts in a jegged manner 2500 2000 150c 1000 -500 20TASK 5):

MATLAB CODE:

clc;

clear all;

close all;

%%%%%%%%%% the threshold value

Trshold = input('Please enter the error threshold:')

xvl = linspace(-2*pi,2*pi);

cos_trm = ones(size(xvl));

cos_appx = cos_trm;

nvl = 2;

xsqrd = xvl.^2*nvl;

%%%%%%%% Calculation of the approximation

while abs(cos_trm(end)) > Trshold

cos_trm = - cos_trm.*xsqrd./factorial(nvl);

cos_appx = cos_appx + cos_trm;

nvl = nvl + 2;

end

%%%%%%%%%% Calculate truncate error

trun_err = abs(cos_appx - cos(xvl));

fprintf('N value: %d \n',nvl);

fprintf('Mean truncation error: %0.6f \n',mean(trun_err));

fprintf('The error is: %0.6f \n', trun_err);

%%%%%%%%%%%% Perform the plot

plot(xvl,trun_err)

MATLAB O/P:

0 5 1 し0 40

Add a comment
Know the answer?
Add Answer to:
Task 4 Many real world objects travel in a jagged manner that is best represented by piecewise fu...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • How to do question B 2,3,4,5? 3. a) Find the solution v ote ordinary diferetinl equation with the initial coditions: b)...

    How to do question B 2,3,4,5? 3. a) Find the solution v ote ordinary diferetinl equation with the initial coditions: b) i) Recast our third ord ODE into a system af first order ODEs af the formA.v, where v' = dv/dz f(v) and v = (y, y,y")". You should show all working to find the corresponding matrix A. Do not solve the system. 4 mark Solve it only by hand and show your complete work. Do not use a calculator...

  • Task The task for this assignment is to have the following user-defined data type: struct rgb...

    Task The task for this assignment is to have the following user-defined data type: struct rgb { unsigned char red; unsigned char green; unsigned char blue; }; be able to be: read in from a stream (e.g., std::cin), i.e., write: std::istream& operator >>(std::istream& is, rgb& colour); (see below) written out to a stream (e.g., std::cout), i.e., write: std::ostream& operator <<(std::ostream& os, rgb const& colour); (see below) stored in a container, e.g., std::vector<rgb>, std::array<rgb,16>; (see below) processed via algorithms (and other...

  • the code in the photo for this I.V.P dy/dx= x+y. y(0)=1 i need the two in the photo thank you New folder Bookmark...

    the code in the photo for this I.V.P dy/dx= x+y. y(0)=1 i need the two in the photo thank you New folder Bookmarks G Google dy/dx x+y, y(0)=1 2 h Exact Solution 1.8 Approximate Solution Mesh Points 1.6 -Direction Fied 1.4 1.2 1 0.8 04 0.2 0.3 0.1 0 X CAUsersleskandara\Desktop\New folder emo.m EDITOR PUBLISH VEW Run Section FILE NAVIGATE EDIT Breakpoints Run Run and FL Advance Run and Advance Time BREAKPOINTS RUN 1 - clear all 2 clc 3-...

  • i need help with a mips program to to covert roman numerals to real numbers Lab 4: Roman Numeral Conversion Part A: Due...

    i need help with a mips program to to covert roman numerals to real numbers Lab 4: Roman Numeral Conversion Part A: Due Sunday, 19 May 2019, 11:59 PM Due Friday, 24 May 2019, 11:59 PM Part B: Minimum Submission Requirements Ensure that your Lab4 folder contains the following files (note the capitalization convention): o Diagram.pdf o Lab4. asm O README.txt Commit and push your repository Lab Objective In this lab, you will develop a more detailed understanding of how...

  • 10. Write a one-page summary of the attached paper? INTRODUCTION Many problems can develop in activated...

    10. Write a one-page summary of the attached paper? INTRODUCTION Many problems can develop in activated sludge operation that adversely affect effluent quality with origins in the engineering, hydraulic and microbiological components of the process. The real "heart" of the activated sludge system is the development and maintenance of a mixed microbial culture (activated sludge) that treats wastewater and which can be managed. One definition of a wastewater treatment plant operator is a "bug farmer", one who controls the aeration...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT