My code fails to get value for M (M and K should be very small numbers, close to zero I believe).

5 views (last 30 days)
Here is my code, it works, but it doesn't give back the right value for M. It has worked for other problems, maybe something is different, or maybe my "g" should be different?
syms x K M c1 c2 c3 c4
x0 = [0,0,0,0];
y0 = [1,200,-80,900];
coeff = [1,-0.02,12.5,-0.058,27.77];
rx = -0.05*exp(0.005*x)*cos(11.7*x) + 0.07*exp(0.005*x)*sin(11.7*x);
y_new = Examprac(x0,y0,coeff,rx);
then the function is here below:
function y = Examprac(x0,y0,coeff,rx)
syms x c1 c2 c3 c4 K M
yp = 2*K*cos((117*x)/10)*exp(x/200) + 2*M*sin((117*x)/10)*exp(x/200);
yp_der1 = diff(yp);
yp_der2 = diff(yp_der1);
yp_der3 = diff(yp_der2);
yp_der4 = diff(yp_der3);
g = coeff(1)*yp_der4 + coeff(2)*yp_der3 + coeff(3)*yp_der2 + coeff(4)*yp_der1 + coeff(5)*yp == rx;
C = solve(g, [M, K])
M_value = double(C.M);
K_value = double(C.K);
C = [M_value, K_value]
yp = subs(yp,K,C(2))
yp = subs(yp,M,C(1))
y = yp;
end

Answers (1)

Sam Chak
Sam Chak on 17 Dec 2023
You have one equation, 'g', but you are attempting to solve for two unknown variables, M and K. The system is considered underdetermined.
% Equation g
g = coeff(1)*yp_der4 + coeff(2)*yp_der3 + coeff(3)*yp_der2 + coeff(4)*yp_der1 + coeff(5)*yp == rx;
% solve g for M and K
C = solve(g, [M, K])

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!