Simple question on using and specifying equations

4 次查看(过去 30 天)
Hi,
What I'm trying to do is simply solve an equation multiple times. By which I mean substitute the letters for numbers.
So I define my equation: syms x y = (3*x) + 5
Then I want to solve it by calling y and entering a value or an array of x values. Something like:
solve(y,10) or solve(y,x=10) or y(x=10) or y(10)
To solve the equation y for a value of x equal to 10, and return the answer of 35.
It must be very simple.
What I don't want to do is y = (3*10) + 5, because I want to define the equation once at the start of my code and then call it multiple times afterwards. So I can quickly investigate the effect of using different equations.
thanks in advance.
Greg

采纳的回答

Azzi Abdelmalek
Azzi Abdelmalek 2013-9-5
编辑:Azzi Abdelmalek 2013-9-5
syms x
y = 3*x + 5
out1=subs(y,10) % The result is a sym class
out2=double(out1) % the result is double

更多回答(1 个)

Andrei Bobrov
Andrei Bobrov 2013-9-5
>> y = @(x)3*x+5;
>> y(10)
ans =
35

类别

Help CenterFile Exchange 中查找有关 Function Creation 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by