How to fix "Number of equations greater than number of indeterminates. Trying heuristics to reduce to square system." error.
조회 수: 20 (최근 30일)
이전 댓글 표시
I have a second order differential that needs solvingand am getting the error listed in the title. It is related to solving a mass-spring-damper system with a non-zero forcing term. Any advice on what is causing the problem and/or could fix it would be greatly appreciated.
clear
clc
close all
m = 10;
k = 160;
t = 0:0.1:50;
b = 0;
F = 200*sin(2*pi*t);
x_0 = -3;
x_dot_0 = 0;
syms x(t)
Dx = diff(x,1);
D2x = diff(x,2);
x = dsolve(F-D2x+(b/m)*Dx+(k/m)*x ==0, x(0) == x_0, Dx(0) == x_dot_0, 't');
x_fun = matlabFunction(x);
x_dot_fun = matlabFunction (diff(x));
x_t = x_fun(time);
v_t = x_dot_fun(time);
plot(t, x_t);
댓글 수: 0
채택된 답변
Star Strider
2024년 2월 8일
편집: Star Strider
2024년 2월 8일
There are a few problems you will likely want to fix.
In the interim, try this —
syms x(t) t
m = 10;
k = 160;
% t = 0:0.1:50;
b = 0;
F = 200*sin(2*pi*t);
x_0 = -3;
x_dot_0 = 0;
Dx = diff(x,1);
D2x = diff(x,2);
x = dsolve(F-D2x+(b/m)*Dx+(k/m)*x ==0, x(0) == x_0, Dx(0) == x_dot_0, 't');
x_fun = matlabFunction(x);
x_dot_fun = matlabFunction (diff(x));
time = 0:0.1:50;
x_t = x_fun(time);
v_t = x_dot_fun(time);
figure
plot(time, x_t)
hold on
plot(time, v_t)
hold off
grid
% set(gca,'YScale','log')
.
댓글 수: 0
추가 답변 (1개)
John D'Errico
2024년 2월 8일
편집: John D'Errico
2024년 2월 8일
You need to understand what was wrong in your forumulation. You want to solve this system using symbolic tools.
% define some constants
m = 10;
k = 160;
b = 0;
% t = 0:0.1:50;
But, by defining t as a vector of discrete elements, that circumvents what you want to do. Your goal was to use dsolve. t and x should be SYMBOLIC variables, not a discrete vector. I think new users seem to often get confused between a vector of elements like you did with t, and then create F, as another vector. F was not a function as you created it, but just another discrete vector of elements.
This next line creates the symbolic variable t, and an unknown function x(t).
syms x(t)
And now we can create F, a forcing term which is a function of t.
F = 200*sin(2*pi*t);
x_0 = -3;
x_dot_0 = 0;
Dx = diff(x,1);
D2x = diff(x,2);
Now you can indeed perform the solve. There is no need to have the 't' at the end of the call to dsolve though.
x = dsolve(F-D2x+(b/m)*Dx+(k/m)*x ==0, x(0) == x_0, Dx(0) == x_dot_0)
x is now a function that satisfies the differential equation, as well as the indicated boundary conditions. You can now do anything with x that you wish, even substitute in a set of discrete values for t, if that is your wish.
Remember though, don't get mixed up in what you are doing. That was your fundamental problem here. The difference between a vector of elements and a function is a subtle one, but something important to understand.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!