ASSIGNING A VALUE TO A VARIABLE

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 Commenti

Stephen23
Stephen23 il 2 Dic 2019
Modificato: Stephen23 il 2 Dic 2019
Numeric computations: yes when you define its as a function input, otherwise no.
Symbolic calculations: yes.
Which do you want to do?
symbolic.
with an example please
thanks
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

Accedi per commentare.

 Risposta accettata

f = @(t) 5*(t-32)/9
or
syms t
f = 5*(t-32)/9

9 Commenti

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.
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 il 2 Dic 2019
Modificato: KALYAN ACHARJYA il 2 Dic 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])
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.
Thanks
Matt J
Matt J il 2 Dic 2019
@henry, if you consider your question answered, you should Accept-click the answer you prefer.
din't see accept on steven lords answer, so I had to accept another answer.

Accedi per commentare.

Più risposte (0)

Prodotti

Tag

Community Treasure Hunt

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

Start Hunting!

Translated by