theres only one positive root for the equation 4cos(x) − ex = 0 for [0,1] domain. use a parabolic function calculated through interpolation to find the approximation for this root. you can choose whatever points you want.
any idea on how to solve this? thanks yall in advance!

댓글 수: 4

Matt J
Matt J 2021년 11월 22일
what points have you chosen?
xbhax
xbhax 2021년 11월 22일
y = [-4.71 -1.51]; but i might be missing one bc its parabolic i guess? any suggestions?
James Tursa
James Tursa 2021년 11월 22일
편집: James Tursa 2021년 11월 22일
Are you supposed to pick any three points you want, fit a parabola to those points, and then find the root of that parabola in the [0,1] domain? Can you use the MATLAB polyfit( ) and roots( ) functions for this? Or are you supposed to be using hand-written code?
xbhax
xbhax 2021년 11월 22일
no, i cant use polyfit nor roots for this... and yes to the 1st question :)

댓글을 달려면 로그인하십시오.

 채택된 답변

James Tursa
James Tursa 2021년 11월 22일
편집: James Tursa 2021년 11월 22일

1 개 추천

Without seeing the text of your assignment, I would presume that this is the outline of what you are supposed to do:
1) Define the function y(x) = 4*cos(x) − exp(x)
2) Pick three points of this function near the desired root in interval [0,1], e.g. (0,f(0)), (0.5, f(0.5)), (1,f(1))
3) Fit a parabola to those three points
4) Find the root of that parabola in the [0,1] interval
Steps 1 and 2 are very easy. Step 3 would have been very easy with polyfit( ), but it is still easy to solve for arbitrary parabola coefficients using a hand written algorithm. Just ask yourself if you have three points (x1,y1,), (x2,y2), and (x3,y3), how would you write the equation of a parabola that passed through these three points? That would give you three equations in three unknowns (the parabola coefficients a, b, c). Then step 4 is easy with your own quadratic formula or other quadratic root code.
See if you can figure out step 3 and come back with any problems you might have.

댓글 수: 4

James Tursa
James Tursa 2021년 11월 22일
편집: James Tursa 2021년 11월 22일
Start with a generic parabola expression
y = a*x^2 + b*x + c
You have three points on this parabola, (x1,y1), (x2,y2), and (x3,y3). So plug them in to get three equations:
y1 = a*x1^2 + b*x1 + c
y2 = a*x2^2 + b*x2 + c
y3 = a*x3^2 + b*x3 + c
You know all the x and y values, so rewrite this as a matrix equation for the unknowns a, b, c:
Y = [some matrix] * [a;b;c]
Now you've got a matrix expression and you are trying to find the vector [a;b;c]. Do you know how to solve a linear system using MATLAB? This is the approach I was steering you towards.
But if you were directed to use a different approach or if this isn't really the problem you are supposed to be solving, you will need to let us know. Maybe post the text of your assignment.
Heyy, thank you very much for your reply! followed step by step and i think i got it...
This is what ive got so far
syms x
f = @(x) (4.*cos(x) - exp(x));
x = [0,0.5,1];
y = [f(0),f(0.5),f(1)];
a = f(x(1))
b = f(x(2))
c = f(x(3))
% polyfit(x,y,2) -> checking
p = fLagrange(x,y);
p = simplify(p);
p = vpa(p,5)
P = [0,1];
vp = subs(p,P)
one last question is how do i find the approximation for the root if i dont know the x value? thank you!
James Tursa
James Tursa 2021년 11월 22일
편집: James Tursa 2021년 11월 22일
I was using a, b, and c to denote the coefficients of the quadratic function. This doesn't match what you have for a, b, and c above.
To solve for the roots of a quadratic function, you could simply use the quadratic formula. That will give you the x value approximation of the root to the original function.
xbhax
xbhax 2021년 11월 22일
got it! thanks a lot! :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Spline Postprocessing에 대해 자세히 알아보기

질문:

2021년 11월 22일

댓글:

2021년 11월 22일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by