Login

Welcome, Guest. Please login or register.

October 09, 2025, 03:05:57 am

Author Topic: ENG1060 Computing  (Read 44621 times)  Share 

0 Members and 1 Guest are viewing this topic.

xZero

  • Victorian
  • Forum Leader
  • ****
  • Posts: 898
  • Respect: +68
Re: ENG1060 Computing
« Reply #150 on: May 10, 2011, 11:30:39 pm »
0
with lab7 q5 b) and c), we use the z values from the table given instead of the polyfit value right? if so I got 0.8102 for part c which doesn't seem right :S

Edit: ok im a retard... i used x-values in my simpson's rule instead of z
« Last Edit: May 10, 2011, 11:33:04 pm by xZero »
2009: Chinese SLA
2010: English, Maths method[45,A+ A+ A+], Specialist maths[44,A+,A,A+], Physics[40,A,A+,A+], Psychology Atar:94.75
2011-2015: Bachelor of Aerospace Engineering/Science @ Monash

Methods/Spesh/Physics tuition

JinXi

  • Victorian
  • Forum Leader
  • ****
  • Posts: 818
  • Respect: +90
  • School: Camberwell High School
  • School Grad Year: 2010
Re: ENG1060 Computing
« Reply #151 on: May 10, 2011, 11:35:56 pm »
0
with lab7 q5 b) and c), we use the z values from the table given instead of the polyfit value right? if so I got 0.8102 for part c which doesn't seem right :S

Edit: ok im a retard... i used x-values in my simpson's rule instead of z

what rule did u use for part c? I used 1 single appl trapezoid and 2 simpson 1/3.

Gonna try some other combinations and see which one's the most accurate..

And yeah I think we're supposed to use the z-values from the tables. Not so sure about this though-.-

Edit: the Combination above doesn't work :P
« Last Edit: May 10, 2011, 11:40:04 pm by JinXi »
Monash B.Aero Eng/Sci Discontinued in Sem2 2012 [2011-2015]

"I will always choose a lazy person to do a difficult job… because, he will find an easy way to do it." ~ Bill Gates
^ SNORLAX, I chooosee You!!!

xZero

  • Victorian
  • Forum Leader
  • ****
  • Posts: 898
  • Respect: +68
Re: ENG1060 Computing
« Reply #152 on: May 10, 2011, 11:37:39 pm »
0
i used 1 trapezoid for 0 and 0.1, 3/8 for 0.1 to 0.7 and 1/3 for 0.7 to 1.2 and my result is within 0.05%
2009: Chinese SLA
2010: English, Maths method[45,A+ A+ A+], Specialist maths[44,A+,A,A+], Physics[40,A,A+,A+], Psychology Atar:94.75
2011-2015: Bachelor of Aerospace Engineering/Science @ Monash

Methods/Spesh/Physics tuition

sajib_mostofa

  • Victorian
  • Forum Leader
  • ****
  • Posts: 829
  • Respect: +6
Re: ENG1060 Computing
« Reply #153 on: May 10, 2011, 11:49:48 pm »
0
Cheers for that man. If I don't ask the user for the number of segments after the rule, then where should I ask them? Also was the m-file for this Q lengthy?

Just ask for the value of n after the rule had been chosen.

Eg if rule == 1
          n = input('.......')
          I = comtrapz(func,a,b,n);
    elseif rule == 2
          n = input('....')
             if
                 *Nested Loop here in case the user enters an odd number of segments
             end
          I = compsimpson1_3(func,a,b,n);
    end
And my M-File was about 50 lines with quite detailed comments. Probably 3x lines of pure code.

To repeat the calculation for the whole thing, do you need to use a while loop before or after this piece of code ^^ ?

JinXi

  • Victorian
  • Forum Leader
  • ****
  • Posts: 818
  • Respect: +90
  • School: Camberwell High School
  • School Grad Year: 2010
Re: ENG1060 Computing
« Reply #154 on: May 10, 2011, 11:54:04 pm »
0
Cheers for that man. If I don't ask the user for the number of segments after the rule, then where should I ask them? Also was the m-file for this Q lengthy?

Just ask for the value of n after the rule had been chosen.

Eg if rule == 1
          n = input('.......')
          I = comtrapz(func,a,b,n);
    elseif rule == 2
          n = input('....')
             if
                 *Nested Loop here in case the user enters an odd number of segments
             end
          I = compsimpson1_3(func,a,b,n);
    end
And my M-File was about 50 lines with quite detailed comments. Probably 3x lines of pure code.

To repeat the calculation for the whole thing, do you need to use a while loop before or after this piece of code ^^ ?


It has to cover the Whole piece of code so it starts before and ends after =)
Monash B.Aero Eng/Sci Discontinued in Sem2 2012 [2011-2015]

"I will always choose a lazy person to do a difficult job… because, he will find an easy way to do it." ~ Bill Gates
^ SNORLAX, I chooosee You!!!

sajib_mostofa

  • Victorian
  • Forum Leader
  • ****
  • Posts: 829
  • Respect: +6
Re: ENG1060 Computing
« Reply #155 on: May 10, 2011, 11:55:24 pm »
0
Thanks for all the help man.  :)

sajib_mostofa

  • Victorian
  • Forum Leader
  • ****
  • Posts: 829
  • Respect: +6
Re: ENG1060 Computing
« Reply #156 on: May 11, 2011, 06:24:50 pm »
0
Can anyone tell me what value of the integral they got for 5a and b?

JinXi

  • Victorian
  • Forum Leader
  • ****
  • Posts: 818
  • Respect: +90
  • School: Camberwell High School
  • School Grad Year: 2010
Re: ENG1060 Computing
« Reply #157 on: May 11, 2011, 09:35:49 pm »
0
with lab7 q5 b) and c), we use the z values from the table given instead of the polyfit value right? if so I got 0.8102 for part c which doesn't seem right :S

Edit: ok im a retard... i used x-values in my simpson's rule instead of z

Actually read the question again and for b and c, it said "Write an M-file that evaluates the integral" and "Modify the M-file in part (a) to evaluate the integral"
Monash B.Aero Eng/Sci Discontinued in Sem2 2012 [2011-2015]

"I will always choose a lazy person to do a difficult job… because, he will find an easy way to do it." ~ Bill Gates
^ SNORLAX, I chooosee You!!!

sajib_mostofa

  • Victorian
  • Forum Leader
  • ****
  • Posts: 829
  • Respect: +6
Re: ENG1060 Computing
« Reply #158 on: May 11, 2011, 09:52:12 pm »
0
Can anyone help me with Q4a of lab7? I don't understand why my loop keeps on returning a value of n = 1

% function inputs
a = -2;
b = 4;
func = @(x) 1-x-4*x.^3+2*x.^5;

% Analysing analytically
I_1 = 1104;

n = 1;
I = comtrapz(func,a,b,n);
error = (I_1 - I)/I;
while error<0.01
    n = n+1;
end


xZero

  • Victorian
  • Forum Leader
  • ****
  • Posts: 898
  • Respect: +68
Re: ENG1060 Computing
« Reply #159 on: May 11, 2011, 10:04:09 pm »
0
while error<0.01
    n = n+1;

after adding a segment, you're suppose to recalculate the estimated integral and error within the while loop

Actually read the question again and for b and c, it said "Write an M-file that evaluates the integral" and "Modify the M-file in part (a) to evaluate the integral"

I just evaluated the integral using the datapoints given oO
2009: Chinese SLA
2010: English, Maths method[45,A+ A+ A+], Specialist maths[44,A+,A,A+], Physics[40,A,A+,A+], Psychology Atar:94.75
2011-2015: Bachelor of Aerospace Engineering/Science @ Monash

Methods/Spesh/Physics tuition

sajib_mostofa

  • Victorian
  • Forum Leader
  • ****
  • Posts: 829
  • Respect: +6
Re: ENG1060 Computing
« Reply #160 on: May 11, 2011, 10:34:47 pm »
0
while error<0.01
    n = n+1;

after adding a segment, you're suppose to recalculate the estimated integral and error within the while loop

Actually read the question again and for b and c, it said "Write an M-file that evaluates the integral" and "Modify the M-file in part (a) to evaluate the integral"

I just evaluated the integral using the datapoints given oO

I tried but the loop isn't ending

xZero

  • Victorian
  • Forum Leader
  • ****
  • Posts: 898
  • Respect: +68
Re: ENG1060 Computing
« Reply #161 on: May 11, 2011, 10:52:59 pm »
0
type the code up if you're still having problem with it
2009: Chinese SLA
2010: English, Maths method[45,A+ A+ A+], Specialist maths[44,A+,A,A+], Physics[40,A,A+,A+], Psychology Atar:94.75
2011-2015: Bachelor of Aerospace Engineering/Science @ Monash

Methods/Spesh/Physics tuition

sajib_mostofa

  • Victorian
  • Forum Leader
  • ****
  • Posts: 829
  • Respect: +6
Re: ENG1060 Computing
« Reply #162 on: May 11, 2011, 10:58:46 pm »
0
% function inputs
a = -2;
b = 4;
func = @(x) 1-x-4*x.^3+2*x.^5;

% Analysing analytically
I_1 = 1104;

n = 1;
I = comtrapz(func,a,b,n);     % Composite trapezoidal function
error = (I_1 - I)/I;
while error<0.01
    n = n+1;
    I = comtrapz(func,a,b,n);     
    error = (I_1 - I)/I; 
end

JinXi

  • Victorian
  • Forum Leader
  • ****
  • Posts: 818
  • Respect: +90
  • School: Camberwell High School
  • School Grad Year: 2010
Re: ENG1060 Computing
« Reply #163 on: May 12, 2011, 12:30:54 am »
0
% function inputs
a = -2;
b = 4;
func = @(x) 1-x-4*x.^3+2*x.^5;

% Analysing analytically
I_1 = 1104;

n = 1;
I = comtrapz(func,a,b,n);     % Composite trapezoidal function
error = (I_1 - I)/I;
while error<0.01
    n = n+1;
    I = comtrapz(func,a,b,n);      
    error = (I_1 - I)/I;  
end

lol you forgot an absolute sign. I_1 will always be smaller than I which results in a -ve number, which will always be smaller than 0.01 hence an infinite loop  :)

Just add the abs() for your error and it should work fine.

Edit: Your Inequality sign is also the wrong way around. If you did that abs already, the error will be larger than 0.01 at the 1st iteration and hence the loop stops, since what you're loop is doing is run WHIle the Error is < 0.01, when it should run when it's >0.01.

« Last Edit: May 12, 2011, 12:36:29 am by JinXi »
Monash B.Aero Eng/Sci Discontinued in Sem2 2012 [2011-2015]

"I will always choose a lazy person to do a difficult job… because, he will find an easy way to do it." ~ Bill Gates
^ SNORLAX, I chooosee You!!!

sajib_mostofa

  • Victorian
  • Forum Leader
  • ****
  • Posts: 829
  • Respect: +6
Re: ENG1060 Computing
« Reply #164 on: May 12, 2011, 12:35:19 am »
0
Thanks for that man, working fine now  :D