defining constants in a equation
조회 수: 5 (최근 30일)
이전 댓글 표시
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
Keshav Dev Singh
2011년 6월 29일
Can you explain your question little more.I am not understanding
if it is constant then why need to change its value?
답변 (4개)
Paulo Silva
2011년 6월 29일
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
Walter Roberson
2011년 6월 29일
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
samira
2011년 6월 29일
댓글 수: 1
Paulo Silva
2011년 6월 29일
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
2011년 6월 29일
댓글 수: 2
Paulo Silva
2011년 6월 29일
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
2011년 6월 29일
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.
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!