0 views

Uploaded by coolsuername

Matlab

- Array
- Array
- 1-s2.0-S1877050913005528-main
- LVCore1 CourseManual English Sample
- Elec 342 Lab1
- Week 13- Arrays Intros
- C++ practical
- L5 - Lists
- c Question
- fr1
- Arrays
- VB Practical file index
- R RStudio Basics
- Day 06 Redefines Renames Arrays Search
- Java OOP Arrays and Exceptions
- Java Programming Examples 140117111234 Phpapp02
- Factorial using Recursion Posted by Saurabh on March 7th, 2010 As a simple rule of recursion, any function can be computed using a recursive routine if : 1. The function can be expressed in its own form. 2. There exists a termination step, the point at which f(x) is known for a particular ‘x’. Therefore to write a recursive program for the factorial of any number, we have to express the factorial function in a recursive form using the above 2 rules : 1. fact(n) = fact(n-1)*n (recursive definition of factorial). 2. if n=1, return 1 (termination step). Using these 2 rules, the recursive program of factorial can be coded very easily as shown : #include "stdio.h" fact(int n) { int factorial; if(n==1) return 1; else factorial=fact(n-1)*n; return factorial; } main() { int num,factorial; printf("Enter any number : "); scanf("%d",&num); factorial=fact(num); printf("The factorial of %d is %d ",num,factorial); return 0; } //////
- PharmaSUG-2012-AD29
- Optimization in the world of 64-bit errors
- MATLAB Tutorial

You are on page 1of 5

CSE 1560

Sample Midterm

Wed. Mar. 30, 2014

A 40

B 60

1

Question 1. [40 points]

1. [5 points] What would the value of the following expression be if the prece-

dence was from right to left

1>2<=3

if precedence was from right to left:

2<=3 evaluates to 1 (true)

1>1 evaluates to 0 (false)

1>2 evaluates to 0 (false)

0<=3 evaluates to 1 (true)

2. [5 points] How does one get the handle to the sine function in Matlab.

@sin

Either:

the only function in a function file callable from outside the file

Or:

The one function in the function file that has the same name as the file

C) if we want a plot with 100x100 points.

All three have size 100x100

1 + 3x + x 3

in Matlab

1, 0, 3, 1

Either:

convolution

Or:

multiplies polynomials

7. [5 points] What is the size of the vector returned by root(p) if p has size 5

4

2

8. [5 points] Give an example of an anonymous function.

Any of the following:

@(x)sin(x)/x

@(y)y-1

@(y)1

Question 2.

[60 points]

1. [10 points] What is the bug with the following Matlab code

function [ A ] = buggyfun(B)

%BUGGYFUN is buggy

B = inv(A)+1;

return;

end

A and B are switched

2. [10 points]

What is the bug with the following Matlab code

V = rand(1,10)

for i=1:10

V(i) = V(i-1)ˆ2;

end

When i==0 (first iteration) V(i-1) is V(0) and Matlab will report

an “array out of bounds” error.

3

3. [20 points]

Write a simple Matlab function named vecint that integrates a vector. The pro-

cedure accepts one argument, a column vector V and returns another vector. Ev-

ery element of the new vector is the sum of all previous elements in the original

vector.

function [ Vo ] = vecint( Vi )

% Comments not necessary

N = length(Vi);

Vo = zeros(N,1);

Vo(1) = Vi(1);

for i=2:N

Vo(i) = Vo(i-1)+Vi(i);

end;

end

4

4. [20 points]

Write a simple matlab procedure named mergevec that accepts two arguments,

both of them column vectors. These Vectors are assumed sorted and not necessar-

ily of equal size. The procedure returns another vector, with size equal to the sum

of the sizes of the two original vectors. The new vector contains the elements of

both original vectors sorted.

function [ M ] = mergevec( A, B )

Na = length(A);

Nb = length(B);

N = Na+Nb;

ia=1;

ib=1;

M = zeros(N,1);

for i=1:N

if (ia<=Na)&(ib<=Nb);

if A(ia)<=B(ib);

M(i) = A(ia);

ia = ia+1;

else

M(i) = B(ib);

ib = ib+1;

end;

elseif ia<=Na

M(i) = A(ia);

ia = ia+1;

else

M(i) = B(ib);

ib = ib+1;

end;

end

- ArrayUploaded byAsma Merchant
- ArrayUploaded byGuturu Dhanesh
- 1-s2.0-S1877050913005528-mainUploaded byhidrobh
- LVCore1 CourseManual English SampleUploaded byAsif Basha
- Elec 342 Lab1Uploaded byYu Xiang Zhang
- Week 13- Arrays IntrosUploaded byBesprenPaoloSpiritfmLucena
- C++ practicalUploaded byHumera Gull
- L5 - ListsUploaded byfisnik kololli
- c QuestionUploaded byAman Kamboj
- fr1Uploaded byinconspicuousannie
- ArraysUploaded byHasan Alomari
- VB Practical file indexUploaded byprofessor_manoj
- R RStudio BasicsUploaded byWulandari Amor Ganelsa
- Day 06 Redefines Renames Arrays SearchUploaded bySiddharth Reddy
- Java OOP Arrays and ExceptionsUploaded byJava OOP
- Java Programming Examples 140117111234 Phpapp02Uploaded byViswaprem CA
- Factorial using Recursion Posted by Saurabh on March 7th, 2010 As a simple rule of recursion, any function can be computed using a recursive routine if : 1. The function can be expressed in its own form. 2. There exists a termination step, the point at which f(x) is known for a particular ‘x’. Therefore to write a recursive program for the factorial of any number, we have to express the factorial function in a recursive form using the above 2 rules : 1. fact(n) = fact(n-1)*n (recursive definition of factorial). 2. if n=1, return 1 (termination step). Using these 2 rules, the recursive program of factorial can be coded very easily as shown : #include "stdio.h" fact(int n) { int factorial; if(n==1) return 1; else factorial=fact(n-1)*n; return factorial; } main() { int num,factorial; printf("Enter any number : "); scanf("%d",&num); factorial=fact(num); printf("The factorial of %d is %d ",num,factorial); return 0; } //////Uploaded byTHIRUNEELAKANDAN
- PharmaSUG-2012-AD29Uploaded bySathisKumar
- Optimization in the world of 64-bit errorsUploaded byTatyanazaxarova2
- MATLAB TutorialUploaded byhasunrajja
- Aqa Mpc3 Qp Jun14 CondUploaded byMichael Sharpe
- w16_206_hwk09_solnsUploaded byanthalya
- Arrays.docxUploaded byRam Kumar
- Embedded MATLABUploaded byDhanya Ramaswamy
- 02 Introduction to MATLABUploaded byAknel Kaiser
- FAQS1_150.docUploaded byviktor
- Hack Mud Script TutUploaded byCarlangaslangas
- using_matlab_to_develop_standalone_graphical_user_interface_(gui)_software_packages_for_educational_purposesUploaded byCorneliu Coman
- Long Test Gen Math Section AUploaded byJemarjo Salandanan
- Matlab tutorialUploaded byGeorge Daoud

- cold+call+challenge+scriptUploaded bycoolsuername
- ACB319-UL-1Uploaded bycoolsuername
- Final+Exam+Phys2130+SU15+Version+1+-+Answer+KeyUploaded bycoolsuername
- Physiology of the EyeUploaded bycoolsuername
- Kings Bus ScheduleUploaded bycoolsuername
- LungUploaded bycoolsuername
- B Cell developmentUploaded bycoolsuername
- ACB319-UL-1Uploaded bycoolsuername
- Volunteer opportunityUploaded bycoolsuername
- Body Fluid and Membrane TransportUploaded bycoolsuername
- 3_genome3_2012Uploaded byshadydogv5
- PsychologyUploaded bycoolsuername
- Chapter 7 Part 2Uploaded bycoolsuername
- Chapter 7 Part 1Uploaded bycoolsuername
- Genetics and Genomics NotesUploaded bycoolsuername

- United States v. James Dow Vandivere, 579 F.2d 1240, 10th Cir. (1978)Uploaded byScribd Government Docs
- bhsp2019Uploaded byapi-458114134
- Community Health Nursing 3 (Ansari Notes)Uploaded byMrs Rehan
- SimplicityUploaded byrose ann veloria
- Your Wish is Your Command PDFUploaded bymcdivah
- CLP Talk_08Uploaded byJoram Ray Obiedo
- revisionUploaded byapi-373250983
- Quadratic SumsUploaded bypushmba
- Passport Alchemy 3.0 User ManualUploaded byAnonymous uPG9xzmj
- Heart Disease, Stroke and CholesterolUploaded byimmunotec
- D QualityAssur Schwinger Aug09 (1)Uploaded bymt
- A-Harappan-Site-In-South-India--Ground-Report-from-Keeladi-Madurai.pdfUploaded byMurugesan Palraj
- Universities and Colleges in New ZealandUploaded bystudynz2008
- Market Monetarism 13092011Uploaded byKarunakar
- 11 Ottoman ArchitectureUploaded byourbook
- Right to Privacy (Justice K S Puttaswamy v Union on India )Uploaded byShehzad Haider
- Refleksi (Sir. Rosli)Uploaded byAlis Hafizi
- Customer Value Equation and WorksheetsUploaded bySharmashD
- Yearly Plan Biology Form 4 2015Uploaded byFida
- HRM - Unit-II - 16 MarksUploaded byRam Kumar
- Fixing the Fix by Zandro Rapadas, M.D.C.Uploaded bythecenseireport
- Event Management ProjectUploaded bySatish Singh ॐ
- BBS Crashing Techniques.txtUploaded byAnurag Ranjan
- From the caves and jungles of Hindostan.pdfUploaded byMohammedGooda
- ESH_LG2013.pptUploaded byTeten Rustendi
- AuditUploaded byRupesh More
- Yoga and Gunas Rajo GunUploaded bydineshgomber
- Motivated Forgetting and MisrememberingUploaded bycheeky monkey
- Change LogUploaded byinkabebe
- INTERNATIONAL JOURNAL OF ACADEMIC RESEARCH IN SOCIAL SCIENCES & HUMANITIES, Vol.2, Issue 3, 2016Uploaded byEditor IJARSH