Machine dynamics with Matlab

5 次查看(过去 30 天)
Nikhil A
Nikhil A 2020-6-17
编辑: Black Woods 2022-10-16
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

回答(1 个)

Black Woods
Black Woods 2022-10-16
编辑:Black Woods 2022-10-16
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));

类别

Help CenterFile Exchange 中查找有关 Calculus 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by