please I want to know if it is possible to write an equation containing a variable before writing down the values. e.g V = a+3, before writing down the value of a.

3 commentaires

Stephen23
Stephen23 le 2 Déc 2019
Modifié(e) : Stephen23 le 2 Déc 2019
Numeric computations: yes when you define its as a function input, otherwise no.
Symbolic calculations: yes.
Which do you want to do?
henry tochukwu
henry tochukwu le 2 Déc 2019
symbolic.
with an example please
thanks
henry tochukwu
henry tochukwu le 2 Déc 2019
I was given an assignment with the equation f = 5(t-32)/9 and was asked to insert the equation before assigning a value to the variable t.
i.e f = 5(t-32)/9
then assign a value to t, but it is not working
I want to know if there any process involved

Connectez-vous pour commenter.

 Réponse acceptée

Walter Roberson
Walter Roberson le 2 Déc 2019
f = @(t) 5*(t-32)/9
or
syms t
f = 5*(t-32)/9

9 commentaires

henry tochukwu
henry tochukwu le 2 Déc 2019
when i used the first step this was the result
f = @(t) 5*(t-32)/9
f =
function_handle with value:
@(t)5*(t-32)/9
with function_handle on blue tag
what other step do I need to take in order to now add a value to t in order to get the final answer for f.
henry tochukwu
henry tochukwu le 2 Déc 2019
please I need the answer urgently.
I will greatly appreciate if i can get the answer before the next 12hrs.
Thanks.
KALYAN ACHARJYA
KALYAN ACHARJYA le 2 Déc 2019
Modifié(e) : KALYAN ACHARJYA le 2 Déc 2019
There also you have define t before either. as sybolic variable t or variable @(t) then_function. But yes later you can pass the t value to the solved expression
Define the anonymous function first.
f = @(t) 5*(t-32)/9
Then call f with numeric values for t.
f([-40 0 32 98.6 100 212])
Though in this case I'd probably give the anonymous function a different name and input argument name, to be slightly more descriptive.
tempF2C = @(tempF) 5*(tempF-32)/9;
tempF2C([-40 0 32 98.6 100 212])
henry tochukwu
henry tochukwu le 2 Déc 2019
I greatly appreciate the answer.
It was 100% helpful.
but permit me to ask this last question
what if they are more than one variable?
e.g. c = ((x^2)*t + 5w)/2
thanks.
Anonymous functions can have multiple inputs. They can also "remember" the values variables in the workspace had when they were created so you don't have to specify them as inputs. For this latter point, you cannot change the "remembered" values without recreating the anonymous function; changing the variable the anonymous function "remembered" afterwards won't change the anonymous function's "memory".
n = 2;
f = @(x, y) n*x+y;
f(3, 1) % 2*3 + 1 = 7
f(5, 9) % 2*5 + 9 = 19
n = 5;
f(3, 1) % still 2*3 + 1 = 7, not 5*3 + 1 = 16
f = @(x, y) n*x+y; % This new f now "remembers" n = 5 not n = 2
f(3, 1) % now 5*1 + 1 = 16
For more information on anonymous functions see this documentation page.
henry tochukwu
henry tochukwu le 2 Déc 2019
Thanks
Matt J
Matt J le 2 Déc 2019
@henry, if you consider your question answered, you should Accept-click the answer you prefer.
henry tochukwu
henry tochukwu le 7 Déc 2019
din't see accept on steven lords answer, so I had to accept another answer.

Connectez-vous pour commenter.

Plus de réponses (0)

Produits

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by