NotesWhat is notes.io?

Notes brand slogan

Notes - notes.io

MATLAB HW questions:
From Chapter 7:
1,2,7 and 34
From Chapter 8:
1,2,20,21 and 26.

User build functions
Start with an m file that has nothing on it, and it will have to start with the word function
function[output1, output2,....] = name(input1, input2, .....)
code that relates the input to the out put

TO MAKE:
1st line: function[A] = fives(r,c) % defining line of the function to be created
%A is the output of the function
%r is the first input of the function
%c is the second input of the function
%Code:
A= 5*ones(r,c); <--needs to connect your input to your output.
%Command Window
B= fives(2,4)
B =
5 5 5 5 5
5 5 5 5 5
5 5 5 5 5

%new m file to make a general matrix multiplicator
fuction[output] = multiplicator_of_matrix(r,c,n);
% output is the output of the function
%r is the 1st input of the function
%c is the 2nd input if the function
%n is the 3rd input of the function
%Code:
Output = n*one(r,c);
%Command Window:
c= multiplicator_of_matrix(4,5,3)

c =
3 3 3 3 3
3 3 3 3 3
3 3 3 3 3
3 3 3 3 3

New m file:

function[surface,volume] = ball(radius) % defining line of function that takes radius of the ball and calculates SA & V.

%radius is the only input
%surface and volume are outputs

%Code:

fi radius > 0
surface = 4*pi*radius^2;
volume= 4/3*pi*radius^3;
else
surface = 'error';
volume = 'error';
end

%Command Window

[A,B] = ball(3)
A=
113.0973
B=
113.0973

[A,B] = ball(-1)
A=
'error'
B=
'error'

Output = ball(2)
output = 50.2655 % <----in this case because only one variable was declared the program only gave the answer of one of the variable in this case SA.
[Output1, Output2]= ball(2)

Output1=
50.2655
Output2=
33.5103

Matlab Lecture 8 pt. 2

Polynomial a_nX^n +a_n-1 X^n-1 + a_n-2 X^n-2 + ......

p1 = 3
p2 = 2x+1
p3 = x^2 + x + 1

for example x^2 - x +3 is inputed as:
p = [1 -1 3]
and x^2 + 3 is inputed as:
p = [1 0 3] %the zero is there because there is no coefficient that has X^1 in the function therefore the constant for that is 0.

% the 3 function types we will be learning today involve Polyval, roots, and polyfit.

%MATLAB:

clear;clc;

%%%Polyval evaluates the value of a given polynomial for a point or a vector of points.
%%Evaluation of 8x + 1 is written as:

p = [8 1]; %coefficient of the polynomial in order from the highest to the lowest.
x = 0;
a1 = polyval(p,x) %this will evaluate the equation 8x+1 at x=0
a1 =
1
%evaluate -2x^2 + 2x -1
p=[-2 2 -1];
a2 = polyval(p,x)
x = 01:0.01:1
figure(1)
plot(x, x.^2)
figure(2)
plot(x, polyval([1 0 0], x))

%%Evaluate the root of a given polynomial
%%finding the root for
p=[1 -12.2 40,59 -17.015 -71.95 35.88]
ROOTS = roots(p)

%polyfit

ex: p1 = polyfit(x,y,1) <--- (data, data, degree of polynomial you want.
     
 
what is notes.io
 

Notes.io is a web-based application for taking notes. You can take your notes and share with others people. If you like taking long notes, notes.io is designed for you. To date, over 8,000,000,000 notes created and continuing...

With notes.io;

  • * You can take a note from anywhere and any device with internet connection.
  • * You can share the notes in social platforms (YouTube, Facebook, Twitter, instagram etc.).
  • * You can quickly share your contents without website, blog and e-mail.
  • * You don't need to create any Account to share a note. As you wish you can use quick, easy and best shortened notes with sms, websites, e-mail, or messaging services (WhatsApp, iMessage, Telegram, Signal).
  • * Notes.io has fabulous infrastructure design for a short link and allows you to share the note as an easy and understandable link.

Fast: Notes.io is built for speed and performance. You can take a notes quickly and browse your archive.

Easy: Notes.io doesn’t require installation. Just write and share note!

Short: Notes.io’s url just 8 character. You’ll get shorten link of your note when you want to share. (Ex: notes.io/q )

Free: Notes.io works for 12 years and has been free since the day it was started.


You immediately create your first note and start sharing with the ones you wish. If you want to contact us, you can use the following communication channels;


Email: [email protected]

Twitter: http://twitter.com/notesio

Instagram: http://instagram.com/notes.io

Facebook: http://facebook.com/notesio



Regards;
Notes.io Team

     
 
Shortened Note Link
 
 
Looding Image
 
     
 
Long File
 
 

For written notes was greater than 18KB Unable to shorten.

To be smaller than 18KB, please organize your notes, or sign in.