Programingscilab
Programingscilab
Plotting in scilab/Matlab
Creating a plot in Scilab involves several steps. Scilab provides functions for basic and advanccd plottíng.
making it a powerful tool for data visualization. Here's the general procedure:
You need to specify thedata points you want to plot. These can be vectors or matrices. For a 2D plot, you'll
need two vectors:
y sin(x):/Define y as a function of x
plot(x, y);
Scilab allows you to customizethe appearanceofthe plot by setting labels, titles, and styles.
Example
title("Sine Wave'"):
xlabel("'x-axis"):
ylabel('"y-axis"):
Example:
yl= cos(x);
47
Applications using programs such as Matlab/Scilab in
Engineering
MATLAB (Matrix Laboratory) is a
powerful numerical computing
aerospace engineering for solving environment widely used in
complex problems, simulation,
and visualization.
Key Features:
1. Matrix-BasedComputations:
Ideal for handling vectors and matrices, commonly used in aerodynamics, structural
analysis, and orbital mechanics.
2. Built-In Toolboxes:
Aerospace Toolbox and Simulink for light dynamics, control systems, and simulation.
3. Visualization:
1. Flight Dynamics:
2. Orbital Mechanics:
3. StructuralAnalysis:
in aerospace structures.
Analyzing stresses and deformations
4. Control Systems:
autopilots and other control systems.
o Designing and simulating
5. CFD Post-Processing:
(CFD) simulations.
Visualizing results from computationalfluid dynamics
similar capabilities for
numerical
to MATLAB, offering
Scilab is an open-source alternative
computation,simulation, and
visualization.
Scilab
MATLAB
Aspect
Free and open-source
Cost Commercial(requires a licensc)
be extended
Limited but growing, can
Toolboxes Wide range, especially for aerospace
46
Example
uid Flow
EOO Data
float
union Data d:
di 10:
d.f 5.5:
Applications of Unions:
Memory Management: Saves memory when only one member is used at a time.
Data Interpretation: Storing data in multiple formats (e.g., interpreting the same data as int or
float).
Structure Union
spect
Memory Each member has its own memory members
All share the same memory space.
Allocation space.
Size Sum of the sizes of all members. Size of the largest member.
45
/ Input data into the
structure
scant("af', &student.marks):
/Displaydata
printt("---StudentInfomation ---n");
return 0:
Applications of Structures:
Unions
A union is similar toa structure but with a key difference: all members share the same memory loca
data typememberl;
L Declaratiem
Exanple
stract Point
int y
The dot ogerator ()isused to access members ofthe structure for example,
Fullexzmple
Boat markss
43
Advantages ofUsing
Functions and Procedures
1.
Modularity: Code is divided
into smaller, manageable
sections.
2. Reusability: Functions can be reused in multiple parts of the
3. Readability: Makes program.
the progran
casier to understand.
4. Debugging: Errors are casier to
identify and fix.
A pointer is a variable that stores the memory address of another variable. Pointers are a powerfulfeature
in C that allows for direct memory access and manipulation.
A pointer is assigned the address of avariable using the address-of operator (&)
int a = 10;
int *ptr =&a:
The value stored at the memory location can be accessedusing the dereference operator
Applications of Pointers:
Example
42
Predefined in libraries, c.g.. printf, scanf, sqrt.
2. User-defined Functions:
void greet)
printt"Hello, World'n'"'):
return a * b:
Procedures in C
In C, proceduresare conceptually the same as void functions becausethey perform actions but do not
return a value.
Characteristics of Procedures:
They are used for tasks like displaying output or modifying global variables.
#include <stdio.h>
return 0;
void printMessage()
41
FUNCTIONS AND PROCEDURES
In C
programming,functions
reusable code. and
procedures are fundamental
building blocks for writing modular and
A
functionis a block of
result. code designed to perform a specific task.It can take input, process it, and return a
There aretwo
main componentsof a
function:
Function Declaration (Prototype): Tells the compiler about the function name,return type, and
parameters. The syntax for declaration is:
eiurm tvpe function
name(parameter list):
Function definition: Contains the actual code. The syntax for
definition is:
returm type function name(parameter list)
Body ofthefunction
returm value; / Optional, depending on the return type
Example
include <stdio.h
return 0:
intadd(int a, int b)
2. Types of Functions
1. Built-in Functions:
40
for (inti 0:irows; i)!
int numnber 1:
printt("n"):
return 0:
printlCAltitude: %.0f meters,
Pressure: %.2f
Paln", altitude,
pressure);
return 0;
4. NESTED LOOPS
Any of the above loops can be nested within another loop to
handle multi-level iterative processes.
Example
#include <stdio.h
int main()
int rowS:
scanf("%d", &rows);
printf("* "):
printf("n'"):
return 0;
#include <stdio.h>>
int main(0
int rows;
scanf("%d",&rows);
38
printf"Do you want to enter another pair numbers to multiply (YNjny
of
scanf(" %e", &choice):
3. FOR LOOP
Used when the number of iterations is known beforchand.
Syntax:
lcode to be executed
Example
soln
#include <stdio.h>
int main)
float altitude,pressure;
37
2. DO...WHILE
The do. ..whilebehaves almost
exactly like the whileloop but guarantees
body since the condition is checked after at least one execution of the loop
the execution.
Syntax:
do
code to be executed
while (condition):
Use a do...while in place of a while only when the body the loop must execute
of at least one time. The
condition is located at the bottom ofthedo...whileloop, so C can't test the condition until the loop
finishes the first time.
Example
Write aprogram that asks the userfor two numbers and then gives the resulting value if the two inputs are
multiplied. It then asks the user if he or shewould like to multiply two more numbers. As long as the user
keeps typing Y, the program keeps asking for numbers to multiply.Only answering N breaks the loop.
* This program multiplys two numbers and display the result for as long as the user wants.
Answering 'N'
breaks the loop. */
#inchude <stdio.h>
main()
char choice:
do
scanf("%", &num2);:
36