How to fix "Number of equations greater than number of indeterminates. Trying heuristics to reduce to square system." error.
20 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
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 Commenti
Risposta accettata
Star Strider
il 8 Feb 2024
Modificato: Star Strider
il 8 Feb 2024
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 Commenti
Più risposte (1)
John D'Errico
il 8 Feb 2024
Modificato: John D'Errico
il 8 Feb 2024
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 Commenti
Vedere anche
Categorie
Scopri di più su Symbolic Math Toolbox in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!