0% found this document useful (0 votes)
68 views8 pages

Numerical Methods GroupNumber3 - Laboratory1

Numerical lab newton rhapson method

Uploaded by

Josh Barrios
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
68 views8 pages

Numerical Methods GroupNumber3 - Laboratory1

Numerical lab newton rhapson method

Uploaded by

Josh Barrios
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
You are on page 1/ 8
aS oes Name: Guiuan , Jhomel Y. snd Conditional Statements Mesina, Jomel B. coca ealod Rosales ,Roland A. jr Maglaqui, Andrei Miko Ye aa plaAltich Emil, ate Performed: Testor En Roaanel Anan Date Submitted: October 12, 2020 1. Objective(s): ay re oe matrices into MATLAB. ‘0 determine the sum of row, column and diagonal of a matrix usin, s , 1g MATLAB. 1.3 faa a matrix that has same sum of row, column and diagonal of different dimension using 2. Intended Learning Outcomes (ILOs): The students shall be able to: 2.1 Demonstrate scientific thinking and the ability to approach scientific resources intelligently. 2.2 Utilize MATLAB software in loops and conditional statements 23 Infer appropriate conclusions based upon the results of activity. 2.4 Reflect on personal transformation along the TIP graduate attributes, specifically, professional competence and critical thinking skils. 3. Discussion: We now consider how MATLAB can be used to repeat an operation many times and how decision are taken, We shall conclude with a description of a conditional loop structures are by necessity simplistic and, as well see, many of the commands can be reduced to a single line. The true power ‘of computers comes into play when we need to repeat calculations over and over again. In order to help you understand the commands in this activity, itis suggested that you work through the codes on paper. You should play the role of the computer and make sure that you only use values which are assigned at that time. Remember that computers usually ‘operate in a serial fashion and that they can only use a variable once it has been defined and given a value. This kind of thought process is very helpful when designing your own codes. The basic MATLAB loop command is for and it uses the idea of repeating an operation for all the elements of a vector. 4. Procedure: LOOPING STATEMENTS EXAMPLE 1: In the following codes below displays a number “n” and its “n?” ooping.m N = input(* Input a number: *); for ii = 1:N disp({int2str(ii) ' squared equals ' int2str(ii*2)]) end | Write the output below displayed on the command window below n= n= 10 Lequared # equal 10 | | squared 1» eaves "0 1 uence gyi g 1 gqueee eq + | Wares, “acts ls squared equals & IS suqvared equals 2 JS squared equals 29 je caunee eaves 36) + Squarea eq vals WF a a cenig OF B Sqyarec ears OF & square eaves | We Sqeree equals (00 1. What is the meaning of "int 2stx*? ‘ " t sion tat pre woontng OF “ink acre tk is 8 Gunorion tna Teaue care a__String_inteqey formar a 1:N to ii = 2. What do you observed when you change ii i nuwver ES woe (eee ooo eee eee end end 1. Write the output ofthe following when x = 5 when x =6 when x =9 wtber to b rember © bey pombee beer Number test x © 4 Divisible by x bivistole by © Divisivle Ly 7 Diviniohe by 4 Pie Ly & EXAMPLE 4. (Nested if-statements) The ideas behind nested if statements is made clear by the example below raining = input(‘Input 1 if it is raining, 0 if not’); if raining == 1 money available = input(‘ input money available: ‘); if money available > 20 disp([‘party’]) elseif money available > 10 disp({ ‘cinema’ ]) else disp({‘comedy night on telly’]) end else money_available = input(* input money available: ‘); temperature = input(* input temperature: ‘); if temperature > 70 & money_available > 40 disp({ ‘beach bbq’]) elseif money_available > 10 disp([‘beach’]) else disp([{‘you must be in UK]) end oO EXAMPLE 2: The following codes writes out the seven times table up to ten seven's str ‘times seven is ‘; for j = 1:10 x-743 disp((int2str(j) str intastr(x) 1) end Write the output below Lames 2 > bimes ita Himes > 1 a Fimes 2 1626 peme® ig 96 rise 9 ig 3 remes Fis ag Nemes 26 66 SOY Dew bime VG mes tie 30 CONDITIONAL STATEMENTS EXAMPLE 3: The following codes writes out the seven times table up to ten seven's str = ‘ Divisible by ‘7 \ x = input (‘Number to test: ")7 for j = 2:9 if rem(x,j) == 0 disp([str_int2str(j)]) end 1. Write the output of the following when it is raining and your] When tis not raining and you | when it is not raining and the money available is 18 have no money available temperature is 100 and your money available is 20 Par hy ypu wth oe in VR Oineyna bean EXAMPLE 4. Write out the values of x2 for all positive integer x such that x° < 2000. To do this, we will use the code Panes output xe a 4 while x*3 < 2000 te as disp(x*2) 3G x=xtl; 4G end ty ot Exercises factors 4. Write a program on MATLAB that prints out the value ofthe integers from 1 to an integer (n) and their (Note: To calculate the prime factors of an integer we use the MATLAB command “factor” Code ksinput(‘enter the data/) disp(' factor’) disp(a) for n=1:length(a) if (a(n)>188mod(a(n), 2-0) a(n)=8.5*a(n); elseif (a(n)>1 && ‘Sample display enter the chat ie eacre Sample output ifn = 6, ‘The value of 6! Is equal to 720 2. Write a program on MATLAB which displays the value of an n factorial: input(‘the value of n: '); for fofti; end disp( ‘factorial is’) disp(f) Tre valve op gacrorial is +20 3. Construct a conditional statement which evaluates the function: SE 0, x<0 x, OsxSs1 (@)=)7 x, 12 Code Sample display et Gf x(i) <= 73 ag “4-8-2 oz ade y(i) = -x(4) -35 elseif (x(i) > -3) @& (x(i) < @) y(i) = x(i) + 35 elseif (x(i) > @) 8& (x(i) < 3) y(i) = -2#x(i) + 35 elseif x(i) >= 3 y(i) = @.5*x(4) - 4.53 end end plot (x,y) the following error messages: 1. Please enter a strictly positive integer 2. You entered zero 3. You failed to enter an integer 4. You entered a negative number 3. Write a code which asks the user for an integer and returns the prime factor of that integer and display Code Sample display 5. Conclusion: a - 7 (WE COncwwoed nat anew sjou ewe feeling Camere wlim pe t", ee a nened Femene 6 We can ule NSIEE SP CREME for comin here Wo Ont peg eLOROMM GUNA! HOM CLEVE, ae tye J vor ie we Cm have an GG ele glatemtnt (ade enether IF KE fhatemeat }- ney Comei vena’ exeremenh EME Ha Tp Srobemen © yeu ui Rave gyenver wrtve) over Wha YOY Pragya eHto¥es Go souennl shehentny Lek SE PEST Yo CUAWENE aerer a COTE Condetton to EAPO Mat | 6. Assessment (Rubric for Activity Performance): IT oe BEGINNER “ACCEPTABLE PROFICIENT |/_ORITERIA fl A i Iscore| Activity Skills | [Work that usually needs to Jhave quality of work and __ [Provides work of the | |Quality of work |be checkediredone by [some small errors on the highest quality and answers {| lothers to ensure quality answer lare correct Focus on the [TOUPis rarely focused on |Group is focused on the [Group is consistently stays task |the task and what to be |task and what needs to be focused on the task and ldone ldone most of the time __|what needs to be done [Members do not Members occasionally Members always Process Skis [demonstrate targeted (demonstrate taryeted (demonstrate targeted | process stills. process skils. skills | [IL Work Habits Time [Members finish ahead of Management! [Members do not fish on _|Members finish on time with °° ath complete data Genco ime with incomplete data. incomplete data. Nee te fesiee de Members donot know their [Members have defined Members are on asks and cooperative and|@StS and have no defied Fesponstlis mest of he Pesponsbilies at all ines. jFogperatv® 24 responsiblties. Group ime. Groupconficts are [Group confit are Iconflicts have to be settled |cooperatively managed cooperatively managed at by the teacher. Imost of the time, at tres. (Clean and orderly Clean and orderly INeatness and [Messy workplace during workplace with occasional |workplace at al times lorderiiness [and afer the experiment. |mess during and after the |during and after the lexperiment. experiment. Abilty todo Members require Members require occasional| Members do not need to be renee Supervision by te teacher. |supervision by the teacher. |supervised by the teacher. [Other Comments / Observations: TOTAL SCORE Rating = (Total Score /21)

You might also like