Machine dynamics with Matlab
7 views (last 30 days)
Show older comments
Sir, I have doubt in solving this question from an exercise from edx course. It is Working with Symbolic Expressions and Functions, here I need to find the solution and solve the equation.
Question is in the pic.
syms x; % Define a symbolic variable x
f(x) = -x^3+x^2-x+5; % Define the required function
symEq = solve(f(x)) % Define a suitable equation for the problem
fplot(f,[0,10]) % Plot the function
sols = double(symEq) % Solve the solution
df=diff(f(x))
zero_crossing_complete = double(solve(df==0)) % Get the zero crossings of the equtation
zero_crossing_real = real(zero_crossing_complete) % Only extract the real zero crossings
The solution is as such,
symEq =
root(z^3 - z^2 + z - 5, z, 1)
root(z^3 - z^2 + z - 5, z, 2)
root(z^3 - z^2 + z - 5, z, 3)
sols =
-0.4406 - 1.5696i
-0.4406 + 1.5696i
1.8812 + 0.0000i
df =
- 3*x^2 + 2*x - 1
zero_crossing_complete =
0.3333 - 0.4714i
0.3333 + 0.4714i
zero_crossing_real =
0.3333
0.3333
0 Comments
Answers (1)
Black Woods
on 16 Oct 2022
Edited: Black Woods
on 16 Oct 2022
x = sym('x');
f(x) = [-x^3+x^2-x+5];
figure('WindowStyle','docked');
fplot(f(x),[0,10]);
axis('square')
sols = solve(f(x)==0);
zero_crossing_complete = double(sols);
zero_crossing_real = real(zero_crossing_complete(end,end));
0 Comments
See Also
Categories
Find more on Symbolic Math Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!