defining constants in a equation
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Hi
I want to define some equations and the solve them. How can I define constants in a matrix? By that I am able to change constants and code it.
Thanks samira
1 commentaire
Keshav Dev Singh
le 29 Juin 2011
Can you explain your question little more.I am not understanding
if it is constant then why need to change its value?
Réponses (4)
Paulo Silva
le 29 Juin 2011
Just guessing by the tags, if you are referring to the solve function
syms a b x %your symbolic variables
c=1; %your constant value
solve(a*x^2 + b*x + c) %solve it and get one familiar expression
0 commentaires
Walter Roberson
le 29 Juin 2011
In addition to Paulo's response about subs():
Depending upon your function, you might be able to solve() the matrix symbolically, and then use matlabFunction() to create a MATLAB function that accepts numeric values of the symbols as arguments and calculates a numeric output.
0 commentaires
samira
le 29 Juin 2011
1 commentaire
Paulo Silva
le 29 Juin 2011
make all letters symbolic and use the subs function to replace the letters you want to be constant in the loop
subs(S,old,new)
Just a small remark, use a copy of the function so you can replace values and reuse the initial function for the next loops.
samira
le 29 Juin 2011
2 commentaires
Paulo Silva
le 29 Juin 2011
i is the imaginary unit, it's equal to sqrt(-1)
You get two values for y probably because of the quadratic equation, read this http://en.wikipedia.org/wiki/Quadratic_equation
Walter Roberson
le 29 Juin 2011
In that context, "i" is the square root of negative 1.
Are you sure you want (x-a1)^2 MINUS (y-b1)^2 ? That does not define a circle.
Either way, consider that for real values y, (y-b1)^2 = (abs(y-b1))^2, so your equation inherently maps two different points to the same value. solve() has no way of choosing between the two values unless you give it more information about which is the "right" value for your purpose.
It seems to me that you should probably not be asking for unique y values: two points of intersection is to be expected. Which one you want to use (if you only want one) is going to depend upon context, not upon any inherent property such as (say) which y value is larger.
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!