Unable to solve linear equation
15 ビュー (過去 30 日間)
古いコメントを表示
Hi,
I'm new to Matlab and I've been trying multiple different things to solve a linear system equation.
I trying this right now
clear
a = 1.05
r = 0.60
m = 500
mc = 900
w = (m / 1000) * 9.81
wc = (mc / 1000) * 9.81
syms t2 alpha teta h
eqn1 = (wc * cos(180 - alpha) + t2 * cos(teta)) == 0
eqn2 = w * -1 + wc * sin(180 - alpha) + t2 * sin(teta) == 0
eqn3 = (a / sin(180 - alpha - teta)) - (r / sin(alpha)) == 0
eqn4 = (h / sin(teta)) - (r / sin(90)) == 0
[A, B] = equationsToMatrix([eqn1, eqn2, eqn3, eqn4], [t2, alpha, teta, h])
x = linsolve(A, B)
But I'm getting this error
Error using mupadengine/feval_internal
Unable to convert to matrix form because the system does not seem to be linear.
Error in sym/equationsToMatrix (line 61)
T = eng.feval_internal('symobj::equationsToMatrix',eqns,vars);
My goal ultimetly is to get the values of h, t2, alpha and teta.
I'm kind of confused because my calculator is able to solve this. I dont really get the problem. I'm trying to "automate" the calculations since I will be running this with a bunch of dataset eventually.
I tried using vpasolve() but it gives me response far from the response my calculator gives me (wich makes way more sense in the context)
Thanks for your help.
2 件のコメント
Cris LaPierre
2023 年 7 月 8 日
A good place to start, then, is with how you solve this on your calculator. What do you enter into your calculator for the matrix A and vector b?
James Tursa
2023 年 7 月 8 日
You have sin( ) and cos( ) in your equations, so it doesn't look linear to me either. Also, it looks like you intend the arguments to be degrees since you have 90 and 180 in them. So maybe sind( ) and cosd( ) are more appropriate.
回答 (3 件)
Shivam
2023 年 7 月 8 日
Hello Tristan, "equationsToMatrix" function in matlab used to convert linear equations into matrix form, for eg:-
syms x y z
eqns = [x+y-2*z == 0,
x+y+z == 1,
2*y-z == -5];
[A,b] = equationsToMatrix(eqns)
But I see your equations contain trignometric functions which makes it non-linear system .
You can refer this to solve systems of non-linear equations - fsolve
This is the implemention -
clear
a = 1.05;
r = 0.60;
m = 500;
mc = 900;
w = (m / 1000) * 9.81;
wc = (mc / 1000) * 9.81;
% Define anonymous functions for the equations
eqns = @(x) [
wc * cosd(180 - x(2)) + x(1) * cosd(x(3));
-w + wc * sind(180 - x(2)) + x(1) * sind(x(3));
(a / sind(180 - x(2) - x(3))) - (r / sind(x(2)));
(x(4) / sind(x(3))) - (r / sind(90))
];
% Set a better initial guess for the variables
x0 = [0.1; 30; 30; 0.1];
% Solve the system of equations numerically
options = optimoptions('fsolve', 'Display', 'iter'); % Optional: Display iterative process
x = fsolve(eqns, x0, options);
% Extract the individual variables from the solution
t2 = x(1);
alpha = x(2);
teta = x(3);
h = x(4);
% Display the results
fprintf('t2 = %.4f\n', t2);
fprintf('alpha = %.4f\n', alpha);
fprintf('teta = %.4f\n', teta);
fprintf('h = %.4f\n', h);
0 件のコメント
Walter Roberson
2023 年 7 月 8 日
編集済み: Walter Roberson
2023 年 7 月 8 日
a = 1.05;
r = 0.60;
m = 500;
mc = 900;
w = (m / 1000) * 9.81;
wc = (mc / 1000) * 9.81;
syms t2 alpha teta h
eqn1 = (wc * cosd(180 - alpha) + t2 * cosd(teta)) == 0
eqn2 = w * -1 + wc * sind(180 - alpha) + t2 * sind(teta) == 0
eqn3 = (a / sind(180 - alpha - teta)) - (r / sind(alpha)) == 0
eqn4 = (h / sind(teta)) - (r / sind(90)) == 0
sol124 = solve([eqn1, eqn2, eqn4])
eqn3b = subs(lhs(eqn3)-rhs(eqn3), sol124)
fplot(eqn3b(1,:), [-100 100])
fplot(eqn3b(2,:), [-100 100])
vpasolve(eqn3b(1,:), 50)
vpasolve(eqn3b(2,:), -50)
0 件のコメント
Diwakar Diwakar
2023 年 7 月 8 日
syms t2 alpha teta h
a = 1.05;
r = 0.60;
m = 500;
mc = 900;
w = (m / 1000) * 9.81;
wc = (mc / 1000) * 9.81;
eqn1 = wc * cosd(180 - alpha) + t2 * cosd(teta) == 0;
eqn2 = -w + wc * sind(180 - alpha) + t2 * sind(teta) == 0;
eqn3 = a / sind(180 - alpha - teta) - r / sind(alpha) == 0;
solutions = vpasolve([eqn1, eqn2, eqn3], [t2, alpha, teta]);
t2_sol = solutions.t2;
alpha_sol = solutions.alpha;
teta_sol = solutions.teta;
fprintf('t2 = %.4f\n', t2_sol);
fprintf('alpha = %.4f\n', alpha_sol);
fprintf('teta = %.4f\n', teta_sol);
0 件のコメント
参考
カテゴリ
Help Center および File Exchange で Equation Solving についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!