Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have attached the code where it says the template for this problem. The template is the code. I need help coding this in MATLAB.

image text in transcribedimage text in transcribed

I have attached the code where it says the template for this problem. The template is the code. I need help coding this in MATLAB. This is all the information I have been given. I have attached the code written out as well so it can be copied and pasted.

% note that the "%" sign is for comments and is not an executable statement

% Always fill include your name and date

% Student Name

% Date

%%%%%%%%%%%%%%%%%% Main Part of Script %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% This course will make use 1 and 2 dimensional arrays. lets take a

% look at how to setup the 1 dimensional array in this exercise

numberOfInterations = 2;

myArray = zeros(size(numberOfInterations)); %this sets up a 1D array of size two

for i=1:numberOfInterations

%instructions

myArray(i) = MyMathFunction(i); %this calls the MyMathFunction and stores the result in myArray index i;

end

%%%%%%%%%%%%%%%%%%%%% Functions %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%here is an example of a function that recieves a variable i and returns 2*i;

function [returnValue] = MyMathFunction(i)

returnValue = 2*i;

end

(1) There are three basic MATLAB concepts important for this class. They are the for-loop, arrays, and functions. These are similar in concept to other programming languages such as C# but the syntax is slightly different. Download and study the attached MATLAB script ( ESC1325 MATLABExample Template-1.m ). Then use the template to: (1) Add a function to the script called "GetCube". The function GetCube returns the cubic (i.e., x) of the variable it received. (2) Add a for-loop that repeats 10 times and calls the function "GetCube" on each iteration. That result is stored in an array. Call that array "result". (3) Add another for-loop that sums the values in the array "result" using the instruction "sum = sum + result[i]" where i is the loop index If you can get this down other scripts in this course will be easier to address. Submit your completed script with your assignment. It must be the actual script and not a picture or pdf file. No credit will be awarded if it can not be downloaded and run. $ note that the "?" sign is for comments and is not an executable statement Always fill include your name and date Student Name Date $$$$$$$ Main Part of Script 3999999999% This course will make use 1 and 2 dimensional arrays. lets take a look at how to setup the i dimensional array in this exercise numberOfInterations = 2; myArray = zeros(size (numberOfInterations)); this sets up a 10 array of size two for i=1:numberOfInterations $instructions myArray(i) = MyMathFunction(i); }this calls the MyMathFunction and stores the result in myArray index i; end Functions there is an example of a function that recieves a variable i and returns 2*i; = MyMathFunction(i) = function (returnvalue] returnValue = 2*i; end 1

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Main Memory Database Systems

Authors: Frans Faerber, Alfons Kemper, Per-Åke Alfons

1st Edition

1680833243, 978-1680833249

More Books

Students also viewed these Databases questions

Question

What are the Five Phases of SDLC? Explain each briefly.

Answered: 1 week ago

Question

How can Change Control Procedures manage Project Creep?

Answered: 1 week ago