Programming for Engineers - Module 1
29 Questions
0 Views

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

What must be checked before calculating the inverse of a matrix A in MATLAB?

  • The matrix must be 2x2 in size.
  • The matrix must contain only positive integers.
  • The determinant of the matrix must be non-zero. (correct)
  • The matrix must be square and symmetric.
  • Which of the following MATLAB functions is used to calculate the divergence of a vector field?

  • integral
  • curl
  • gradient
  • divergence (correct)
  • In the MATLAB script for visualizing the gradient of a scalar function, what does the meshgrid function accomplish?

  • It creates a grid of x and y values for plotting. (correct)
  • It initializes a 2D matrix for parameters.
  • It generates random points for the plot.
  • It calculates the function's values over a range.
  • What is the requirement for designing a valid Sudoku matrix in MATLAB?

    <p>Each row, column, and 3x3 sub-grid must contain numbers 1-9 with no repetition.</p> Signup and view all the answers

    What is the outcome when trying to calculate the inverse of a matrix with a determinant of zero in MATLAB?

    <p>An error message is displayed indicating the matrix is singular.</p> Signup and view all the answers

    How do you perform element-wise multiplication of two vectors A and B in MATLAB?

    <p>A .* B</p> Signup and view all the answers

    What command is used to create a 3x3 identity matrix in MATLAB?

    <p>eye(3)</p> Signup and view all the answers

    What is the major difference between a script and a function in MATLAB?

    <p>Functions can return outputs, scripts cannot.</p> Signup and view all the answers

    Which command would you use to label the x-axis as 'Time' in a plot?

    <p>xlabel('Time')</p> Signup and view all the answers

    How would you write a for loop in MATLAB that iterates from 1 to 10?

    <p>for i = 1:10</p> Signup and view all the answers

    Which command is used to read data from a file named 'data.txt'?

    <p>importdata('data.txt')</p> Signup and view all the answers

    What is the purpose of the profiler in MATLAB?

    <p>To analyze performance and identify bottlenecks.</p> Signup and view all the answers

    How can you append new data to an existing text file in MATLAB?

    <p>fopen('filename', 'a'); fprintf(fid, '%f', data)</p> Signup and view all the answers

    What is the formula used to convert Celsius to Fahrenheit in the given function?

    <p>F = (C * 9/5) + 32</p> Signup and view all the answers

    In the kinetic energy calculation, which part of the formula represents the potential energy?

    <p>0.5 * mass * velocity^2</p> Signup and view all the answers

    What variable represents time of flight in the projectile trajectory calculation?

    <p>t_flight</p> Signup and view all the answers

    What is the purpose of the deg2rad function in the projectile motion script?

    <p>To convert degrees to radians</p> Signup and view all the answers

    Which value represents acceleration due to gravity in the projectile motion calculation?

    <p>9.81 m/s^2</p> Signup and view all the answers

    In the quadratic equation script, which of the following is true regarding inputs required from the user?

    <p>Three coefficients must be provided.</p> Signup and view all the answers

    How is the trajectory of the projectile plotted in MATLAB?

    <p>Using the <code>plot</code> function for a 2D graph of distance and height</p> Signup and view all the answers

    What is the significance of the fprintf function in the provided MATLAB scripts?

    <p>To format and display the output nicely</p> Signup and view all the answers

    What formula is used to calculate the roots of a quadratic equation in the provided solution?

    <p>root1 = (-b + sqrt(D)) / (2<em>a); root2 = (-b - sqrt(D)) / (2</em>a);</p> Signup and view all the answers

    What will happen if a user inputs a negative integer for factorial calculation?

    <p>The script will display an error message.</p> Signup and view all the answers

    How is total time in seconds calculated in the script provided?

    <p>total_seconds = hours * 3600 + minutes * 60 + seconds</p> Signup and view all the answers

    In the corrected summation script, which variable name was corrected to achieve the desired output?

    <p>sum</p> Signup and view all the answers

    Which statement is true concerning the discriminant (D) in the quadratic equation solution?

    <p>If D = 0, there is exactly one real root.</p> Signup and view all the answers

    What is the output when the input for hours, minutes, and seconds is 0, 0, and 0, respectively?

    <p>Total time in seconds: 0 seconds</p> Signup and view all the answers

    What type of loop is utilized in the script to calculate the factorial of a number?

    <p>For loop</p> Signup and view all the answers

    What would the script display if the input for n in the factorial script is 5?

    <p>Factorial of 5 is 720</p> Signup and view all the answers

    Study Notes

    Programming for Engineers - Module 1

    • Course name: Programming for Engineers
    • Module: 1
    • Lab: 1 & 2
    • Topic: Introduction to Programming Basics
    • Instructor: Dr. Rupendra Kumar Pachauri
    • Software: MATLAB

    Lab Session - Introduction to Programming Basics

    • Problem 1 (Matrix Operations): Given a matrix A, perform the following tasks:
      • Extract the 9th element into a variable D.
      • Replace the value 30 in matrix A with 50.
      • Calculate the sum and product of all elements in matrix A.
      • Calculate the sum and product of each column in matrix A.
      • Count the number of elements in matrix A.
      • Find the minimum and maximum values for each column in matrix A.
      • Calculate the square of each element in matrix A.
      • Divide each element in matrix A by a value.
      • Add each element of matrix A together.
      • Calculate the square root of the 9th element.
    • Additional Practice Questions:
      • Basic MATLAB operations (variable creation, multiplication of vectors, differences between .* and *).
      • 3x3 identity matrix creation.
      • Matrix concatenation (vertical).
      • Accessing matrix elements (row, column).
      • Script versus function differences.
      • Simple function syntax.
      • Function calls.
      • Plotting (creating a sine wave plot, labeling axes, adding a legend).

    Problem 1 (Series Circuit Resistance)

    • Task: Design a MATLAB program that computes the total resistance of a series circuit with three resistors (R1, R2, R3).
    • Input: The values of the three resistors (R1, R2, and R3) from the user.
    • Output: Total resistance (in ohms).
    • Formula: Rtotal = R1 + R2 + R3

    Problem 2 (Temperature Conversion)

    • Task: Create a MATLAB function to convert a temperature from Celsius to Fahrenheit.
    • Input: Temperature in Celsius.
    • Output: Temperature in Fahrenheit.
    • Formula: Fahrenheit = (Celsius * 9/5) + 32

    Problem 3 (Kinetic Energy Calculation)

    • Task: Design a MATLAB program to compute and display the kinetic energy of a moving object.
    • Input: Mass and velocity of the object.
    • Output: Kinetic Energy (in Joules).
    • Formula: Kinetic Energy = 0.5 * mass * velocity^2

    Problem 4 (Projectile Trajectory)

    • Task: Create a MATLAB script to plot the trajectory path of a projectile.
    • Input: Initial velocity and launch angle.
    • Functionality Script calculates and plots projectile's x and y positions with time using kinematic equations.
    • Parameters: Uses acceleration due to gravity, calculates flight time and creates time intervals.

    Problem 5 (Quadratic Equation Roots)

    • Task: Create a MATLAB script to compute roots of a quadratic equation (ax^2 + bx + c = 0).
    • Input: coefficients a, b, and c from the user.
    • Output: The roots of the equation if possible

    Problem 6 (Time Conversion)

    • Task: Design a MATLAB script to convert a given time (hours, minutes, seconds) to total seconds.
    • Input: Time in hours, minutes, and seconds from the user.
    • Output: Total time in seconds

    Problem 7 (Factorial Calculation)

    • Task: Write a MATLAB script to calculate the factorial of a given non-negative integer using a loop.
    • Input: A non-negative integer from the user.
    • Function: Calculate factorial of the integer
    • Output: Factorial of the integer.
    • Error Handling: Check if the input is non-negative integer.

    Problem 8 (Summation)

    • Task: Correct the given MATLAB script that calculates the sum of the first 10 natural numbers.
    • Problem: Original script used a different variable name and needed correction

    Problem 9 (Matrix Multiplication)

    • Task: Create a MATLAB script multiply two compatible matrices A and B.
    • Input: Matrices A and B as input.
    • Functionality: Script performs matrix multiplication and displays the resultant matrix

    Problem 10 (Matrix Inverse)

    • Task: Program to find the inverse of a 3x3 matrix if it's invertible.
    • Input: A 3x3 matrix (A)
    • Functionality: Calculates and display the inverse if it exists else displays a warning that matrix is non invertible.

    Problem 11 (Divergence Calculator)

    • Task: Calculate the divergence of vector field F(x, y, z) = (x^2, y^2, z^2)
    • Input: Vector field F(x, y, z)
    • Function: MATLAB's divergence function is used.

    Problem 12 (Gradient Visualization)

    • Task: MATLAB script to visualize the gradient of a scalar function f(x, y)=x^2+y^2.
    • Input: The scalar function f(x, y) and its domain
    • Functionality: Creates a 2D plot (x, y) using mesh grid.

    Sudoku Matrix Design

    • Rules: Each row, column, and 3x3 subgrid must contain the numbers 1-9 without repetition.
    • Matrix Dimensions: The Sudoku grid is a 9x9 matrix.

    Studying That Suits You

    Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

    Quiz Team

    Related Documents

    Description

    Test your understanding of the basics of programming with MATLAB in the first module of Programming for Engineers. This lab focuses on matrix operations, including element extraction, value replacement, and various calculations on matrices. Dive into practical MATLAB applications that sharpen your programming skills.

    More Like This

    Use Quizgecko on...
    Browser
    Browser