Notes, summaries, assignments, exams, and exercises for Computer science for University

MATLAB Data Analysis and Trigonometric Plotting

Computer science2.6 KB

MATLAB Statistical Analysis of Student Weights

Analyze the weight of 30 students to find the minimum, maximum, average, standard deviation, and plot a histogram.

>> a=[ 71 82 65 75 77 91 59 84 89 81 73 91 82 75 96 85 69 76 81 92 84 79 77 95 81 79 84 85 76 82]

a = Columns 1 through 12
    71 82 65 75 77 91 59 84 89 81 73 91

Columns 13 through 24
    82 75 96 85 69 76 81 92 84 79 77 95

Columns 25 through 30
    81 79 84 85 76 82

>> max(a)
ans = 96

>> min(a)
ans = 59

>> mean(a)
ans = 80.5333

>> std(a)
ans = 8.4516

>> hist(a)

Plotting Trigonometric Functions in MATLAB

Follow these steps to plot trigonometric functions:

  • Plot the value of the cosine within [0, 2π] with a step of π/20.
  • Label the axes and add
...
Continue reading "MATLAB Data Analysis and Trigonometric Plotting" »

Top-Down Design and Control Structures in Python

Computer science3.35 KB

3/10/16 Notes

Chapter 7/8

Top-Down Design

Takes the most basic aspect of a program and breaks it down into subprograms.

Control Structure

An expression that determines the order in which a program executes.

In Python, this is an if statement.

It can also be a looping statement.

Boolean Expression

A "True or False" program statement.

Composite Data Types

Example:

  • numbers[0] = 1066
  • numbers[1] = 1492
  • numbers[2] = 999
  • numbers[3] = 553
  • numbers[4] = 1892

Example Code:

for i in range(3):
    print(numbers[i])

Arrays

When data is being read into an array, a counter is updated for each operation (e.g., for i in range(5)).

Sequential Search of an Unsorted Array

A sequential search examines each item in turn and compares it to the target item. If it matches, the item is found....

Continue reading "Top-Down Design and Control Structures in Python" »

C Programming Examples: Code Snippets and Explanations

Computer science3.41 KB

C Programming Examples

Here are several C programming examples:

Vector Operations

#include <stdio.h>

void leVetor (int v [] , int tam );
int prodEscalar (int v1 [] , int v2 [] , int tam );

int main (void) {
    int v1 [ DIM ], int v2 [ DIM ];
    int i;
    int prod ;

    leVetor (v1 , DIM );
    leVetor (v2 , DIM );
    prod = prodEscalar (v1 , v2 , DIM );
    printf ("%d\n", prod );
    return 0;
}

void leVetor (int v [] , int tam ) {
    /* Completar */
}

int prodEscalar (int v1 [] , int v2 [] , int tam ) {
    /* Completar */
}

Random Number Generation

#include <stdio.h>
#include <time.h>
#include <stdlib.h>

#define VEZES 10

int main (void) {
    int i , j , k;
    double r;

    srand ( time ( NULL )); /* inicializa
...
Continue reading "C Programming Examples: Code Snippets and Explanations" »

Parallel Execution, Mutex, and Deadlocks in Operating Systems

Computer science3.2 KB

Parbegin / Person Learns

Parbegin is a structure to indicate parallel execution, marking the beginning and end. Selection: A statement dividing sequential execution into parallel streams.

Its general form (Dijkstra):

parbegin Proposition1; Proposition2; Proposition n; person learns

Mutex

Mutex occurs when processes share data, preventing simultaneous access. It applies when a process accesses shared data, allowing concurrent execution of non-conflicting transactions.

Critical Sections

A process accessing shared data is in a critical section. When a process is in a critical section:

  • All other processes are excluded from their critical sections.
  • Other processes can execute outside their critical sections.
  • When a process exits, the next waiting process
...
Continue reading "Parallel Execution, Mutex, and Deadlocks in Operating Systems" »

System Modeling Concepts and Environmental Model Definition

Computer science3.75 KB

System Modeling Fundamentals

A model is an abstract representation of a real object. The first model developed is crucial as it defines the interfaces between the system and its environment. This initial model is known as the environmental model, describing the immediate context in which the system operates according to its objectives.

Components of the Environmental Model

  1. Statement of Purpose (Objectives)

    This is a short and concise textual statement defining the system's purpose.

  2. Context Diagram

    The Context Diagram graphically shows how the system interacts with the environment, making it easy for a user to interpret.

    It is a special case of a Data Flow Diagram (DFD), where a single bubble represents the entire system.

    Important Features Represented:
...
Continue reading "System Modeling Concepts and Environmental Model Definition" »

Essential Excel Features and Pascal Programming Concepts

Computer science4.6 KB

Excel Fundamentals

1. Decrease Indent

Reduces the indentation level of content within a cell.

2. Increase Indent

Increases the indentation level of content within a cell.

Also related: Increase Margin.

3. Orientation

Adjusts the direction of text or objects.

  • Vertical Orientation: Arranges text or objects vertically.

4. Insert Menu Contents

The Insert Menu typically contains options to add various elements to your worksheet:

  • Cells
  • Chart Sheet
  • Symbol
  • Page Break
  • Function
  • Name
  • Comment
  • Image
  • Diagram
  • Object
  • Hyperlink

5. Format Menu Contents

The Format Menu provides options for styling and arranging elements:

  • Cells
  • Rows
  • Columns
  • Sheet
  • Format (e.g., AutoFormat)
  • Conditional Formatting
  • Style

6. Tools Menu Contents

The Tools Menu offers utilities for various tasks:

  • Spelling
  • Reference (
...
Continue reading "Essential Excel Features and Pascal Programming Concepts" »

C Programming: Arrays, Structs, and Pointers Explained

Computer science3.22 KB

1. Defining a Car Structure in C

Define a structure suitable for the following details of a car: Brand, Category (compact, family), Model, Engine Size, and Year.

Answer:

struct Datos_auto {
  char brand[30];
  char model[10];
  char category[30];
  int year;
  int size;
};

4. Array Index Out of Bounds

What happens if you assign a value to an element of an array whose index exceeds the array size?

Answer: It will overwrite data in adjacent memory locations.

5. Array Name Representation

If an array is declared as int list[12];, what does the word list represent?

Answer: It represents the array name (which also acts as a pointer to the first element).

6. Definition of a String in C

In the C language, what is a string?

Answer: A string is a composite data

...
Continue reading "C Programming: Arrays, Structs, and Pointers Explained" »

C Program for Matrix Addition using Arrays and Functions

Computer science3.8 KB

This document presents two methods for implementing matrix addition in C: a monolithic approach within the main function and a modular approach utilizing separate functions for input, calculation, and display. Both examples handle 2D arrays up to 100x100 dimensions.

Method 1: Monolithic Implementation in main()

This initial approach places all logic—input handling, calculation, and output—directly within the main function. The code below has been corrected for proper C syntax, including loop conditions and scanf format specifiers.

Corrected C Code Snippet 1

#include <stdio.h>
#include <stdlib.h>

void main(void) {
    float a[100][100], b[100][100], c[100][100];
    int rows, columns, i, j;

    printf("Enter number of rows: ");
...
Continue reading "C Program for Matrix Addition using Arrays and Functions" »

Essential Python Programming Examples and Algorithms

Computer science4.88 KB

Binary Search Algorithm

The Binary Search algorithm is an efficient way to find a target value within a sorted array.

arr = [10, 20, 30, 40, 50, 60, 70]
key = int(input("Enter number to search: "))

low = 0
high = len(arr) - 1

while low <= high:
    mid = (low + high) // 2

    if arr[mid] == key:
        print("Element found at index", mid)
        break
    elif arr[mid] < key:
        low = mid + 1
    else:
        high = mid - 1
else:
    print("Element not found")

Finding the Largest Element

This snippet demonstrates how to iterate through a list to identify the maximum value.

numbers = [10, 25, 8, 45, 30]

largest = numbers[0]

for i in numbers:
    if i > largest:
        largest = i

print("Largest element is:", largest)

Linear

...
Continue reading "Essential Python Programming Examples and Algorithms" »

C Programming Concepts: Arrays, Functions, Structures, and Stacks

Computer science300.77 KB

1. Arrays: Definition, Types, and Implementation

An array is a collection of elements of the same data type stored in contiguous memory locations. It is used to store multiple values in a single variable and can be accessed using index numbers. The indexing in an array starts from 0. Arrays help manage and process data efficiently, especially when dealing with large volumes of similar data.

Types of Arrays Based on Dimensions

  • One-Dimensional Array: It stores data in a linear list format.
  • Multi-Dimensional Array: It stores data in matrix form (like 2D, 3D arrays), which is useful in applications like image processing and tables.

Types of Arrays Based on Memory Allocation

  1. Static Array:

    The size of the array is fixed at compile-time. Memory is allocated

...
Continue reading "C Programming Concepts: Arrays, Functions, Structures, and Stacks" »