d2jsp
Log InRegister
d2jsp Forums > Off-Topic > General Chat > Homework Help > Matlab Code/programing Need Help
Prev123
Add Reply New Topic New Poll
Member
Posts: 239
Joined: Aug 27 2014
Gold: 0.01
Sep 13 2014 10:58am
Quote (saber_x3 @ Sep 13 2014 12:15pm)
because i asked for the expansion of 1-cosx
doesnt really matter


okay.

For part 2b, I tried using the newton's method but I'm not sure if I'm doin it right or suppose to be using this method to get the accurate answer. any idea on wat I should do

Code
%% PartB
syms x
f= x.^2 - (10^8)*x + 1;
f1= diff(f,x);
x = .5;
tol = 0
dx = tol + 50;
while abs(dx) > tol
x = x - (subs(f,x)/subs(f1,x))
end


This post was edited by TheDiablo3KnowItAll on Sep 13 2014 11:23am
Member
Posts: 7,721
Joined: Oct 11 2008
Gold: 304.00
Sep 13 2014 12:15pm
the real answer comes from 1-cos(x)
ask matlab to just solve for (1-cosx)
don't use another method to approximate it again

error
[(1-cosx) - xx/2]/(1-cosx)

This post was edited by saber_x3 on Sep 13 2014 12:15pm
Member
Posts: 239
Joined: Aug 27 2014
Gold: 0.01
Sep 13 2014 12:19pm
Quote (saber_x3 @ Sep 13 2014 02:15pm)
the real answer comes from 1-cos(x)
ask matlab to just solve for (1-cosx)
don't use another method to approximate it again

error
[(1-cosx) - xx/2]/(1-cosx)


isn't the error= [(xx/2) - (1-cosx)] / (1-cosx)? numerical answer - true answer / true answer
Member
Posts: 7,721
Joined: Oct 11 2008
Gold: 304.00
Sep 13 2014 12:29pm
doesn't really matter, real value is on the bottom is what matters
Member
Posts: 239
Joined: Aug 27 2014
Gold: 0.01
Sep 13 2014 01:48pm
Quote (saber_x3 @ Sep 13 2014 02:29pm)
doesn't really matter, real value is on the bottom is what matters


ok btw we are talkin about 2b, so this is what I did. It gave me 2 roots one being 10^8 and the other one is 0 which is close to exact root of 10^-8.

how do I make it output the true values of the root/find the two solutions accurately

Code
%% PartB
syms x
f= x.^2 - (10^8)*x + 1;
root = solve(f)
Member
Posts: 7,721
Joined: Oct 11 2008
Gold: 304.00
Sep 13 2014 02:45pm
It is using an approximation to solve it
You can try to format your answer to show more digits. I don't know how to format output

I know matlab has solvers in it that you can use for many different things
try the polynomial or quadratic solver, they might be more accurate or exact

errors come from how the program store values, different types/order of multiplying, and the preset desired accruacy
Member
Posts: 239
Joined: Aug 27 2014
Gold: 0.01
Sep 13 2014 04:35pm
Quote (saber_x3 @ Sep 13 2014 04:45pm)
It is using an approximation to solve it
You can try to format your answer to show more digits. I don't know how to format output

I know matlab has solvers in it that you can use for many different things
try the polynomial or quadratic solver, they might be more accurate or exact

errors come from how the program store values, different types/order of multiplying, and the preset desired accruacy


ehh I changed it up and I got this

http://imgur.com/xpz694K

u think this is acceptable?
Go Back To Homework Help Topic List
Prev123
Add Reply New Topic New Poll