Symbolic toolbox substitution causing large values

I am creating a Jacobian matrix for a state space model. I Delcared all the constants and variables as variables in syms. After Jacobian when i substitue the constant values I getting some values which are not the exact values what i want. Can any help me in this?
clc
clear all
syms v T m qa Ta mg tow cv R Va B0 a A0 B C0 c Tg gamma
f1 = qa
f2 = ((Ta-T)/tow)-(T/cv)*(qa/m)*{(R*mg*(1+mg.^2/Va.^2)/Va)+(mg.^2/Va.^2)*(B0*R+2*C0/Tg.^3)-...
((2*c*mg.^3/Va.^3*Tg.^3)*(1+gamma*mg.^2/Va.^2)*exp(-gamma*mg.^2/Va.^2))}
f3 = 0
%to solve the variabes
j = jacobian([f1 f2 f3],[v T m])
var = subs(j,[B0,C0,R,Tg,Va,c,cv,gamma,mg,tow],[4.07*10.^-5,816.58,8.134,295,25*10.^-3,0.07381,20.8040,5.3*10.^-9,144.1832,26.574])

 Réponse acceptée

John D'Errico
John D'Errico le 21 Avr 2022
Modifié(e) : John D'Errico le 21 Avr 2022
A REALLY bad idea is to name your variables things like var, as that is also the name of a terribly useful function.
So your next question will be why does the function var no longer work anymore.
syms v T m qa Ta mg tow cv R Va B0 a A0 B C0 c Tg gamma
f1 = qa
f1 = 
qa
f2 = ((Ta-T)/tow)-(T/cv)*(qa/m)*{(R*mg*(1+mg.^2/Va.^2)/Va)+(mg.^2/Va.^2)*(B0*R+2*C0/Tg.^3)-...
((2*c*mg.^3/Va.^3*Tg.^3)*(1+gamma*mg.^2/Va.^2)*exp(-gamma*mg.^2/Va.^2))}
f2 = 
f3 = 0
f3 = 0
%to solve the variabes
j = jacobian([f1 f2 f3],[v T m])
j = 
var = subs(j,[B0,C0,R,Tg,Va,c,cv,gamma,mg,tow],[4.07*10.^-5,816.58,8.134,295,25*10.^-3,0.07381,20.8040,5.3*10.^-9,144.1832,26.574])
var = 
vpa(var,5)
ans = 
I don't see anything big. Perhaps you don't know about vpa, to convert those numbers into floating point results?

1 commentaire

yes i got the answer thank you very much. I was not aware of vpa.

Connectez-vous pour commenter.

Plus de réponses (0)

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by