"solve" Function

조회 수: 10 (최근 30일)
Patrick Star
Patrick Star 2011년 3월 7일
편집: Walter Roberson 2021년 12월 27일
I'm trying to use the "solve" function to find a variable, but the other variables in the equation are input as opposed to defined. How do I fix this? Here's to illustrate what I'm trying to do using a simplified equation:
x=input('x = ')
y=input('y = ')
z=solve('x+y=z',z)
  댓글 수: 2
Tebikew Alemu
Tebikew Alemu 2021년 12월 27일
How i can write a matlab cod for a funtion
Walter Roberson
Walter Roberson 2021년 12월 27일
편집: Walter Roberson 2021년 12월 27일
Example:
syms x
y(x) = sin(x) - x^3/27 %this is the code for the function
y(x) = 
fplot(y, [-2*pi 2*pi])

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

채택된 답변

Walter Roberson
Walter Roberson 2011년 3월 9일
Did you solve the license problem? Until you have the software installed and licensed, solve() isn't going to work.
The answer you are looking for is along these lines:
syms x y z
xin = input('x =');
yin = input('y =');
zsol = solve('z-y=x', z);
disp(['z = ' char(zsol)]);
znum = double(subs(zsol, {x, y}, {xin, yin}));
disp(['z = ' num2str(znum)]);
  댓글 수: 1
Patrick Star
Patrick Star 2011년 3월 9일
I installed the software and this works. Thanks!

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

추가 답변 (2개)

Andrew Newell
Andrew Newell 2011년 3월 7일
Here is one way:
x=sym(input('x = '))
y=sym(input('y = '))
syms z
z=solve(z-x-y,z)
  댓글 수: 5
Andrew Newell
Andrew Newell 2011년 3월 8일
Oh. I assumed that you were actually using the command "solve", which is in the Symbolic Toolbox.
Walter Roberson
Walter Roberson 2011년 3월 8일
Please check to see whether you are licensed for the symbolic toolbox but perhaps have just not installed it. If you happen to be using the Student Edition than this could be the difficulty.
solve() is part of the symbolic toolbox and requires that toolbox be installed and licensed.

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


Andrew Newell
Andrew Newell 2011년 3월 8일
Is this what you're after?
x=input('x = ')
y=input('y = ')
z = x+y
  댓글 수: 1
Patrick Star
Patrick Star 2011년 3월 8일
In a way, yes. But the equations and variables are a lot more complicated than that and I don't have it already solved. I need to solve for z and find its value, but I can't figure out how to make the solve function give me both; in other words, I have an equation like z-y=x, and I want to input 1 and 2 for x and y and then have the output give me two things:
z = x+y
and
z = 3

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

카테고리

Help CenterFile Exchange에서 Assumptions에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by