필터 지우기
필터 지우기

solve with parameter

조회 수: 2 (최근 30일)
Matus
Matus 2012년 3월 18일
hello, i need to solve the equation with parameter. I have a problem with solution.
First, I wrote easy equation with parameter n.
syms x positive
n=2;
solve(x-n) %equation has this form x-n=0
it works great
then I wrote
n=2;
solve(-n+x)
but the solution was not equal as in the first case.
I dont know what's wrong. Can you help me please. Thank you.
  댓글 수: 2
Alexander
Alexander 2012년 3월 19일
I get the same result in both cases:
ans =
2
I have no idea what's wrong. Could you please share your results?
Matus
Matus 2012년 3월 19일
Sorry Alexander, I wrote a bad code. The problem was when I define
syms x
n=num2str(2);
solve(x-n) %result 2
solve(-n+x) %result 50

댓글을 달려면 로그인하십시오.

채택된 답변

Alexander
Alexander 2012년 3월 19일
Try to avoid num2str during calculations. This will convert the input into a string. A string is basically an array of character codes. If you do anymore calculations with it, it will be treated as an array of values, like in this example
>> A = num2str(12345);
>> A+0
ans =
49 50 51 52 53
The number 50 stands for the character '2'. This is why -n results in -50 in your example above.
  댓글 수: 1
Matus
Matus 2012년 3월 19일
thank you

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by