0

Let's say we have the unknown variable t in enter image description here. How can I define this variable t in Matlab so I can do calculations with it? For example, I'd like to do this:

enter image description here and then form this to t, in the end display the result of variable t.

I have tried to do this with sym and downloaded matlab toolbox addon for it... but it's not working :/

function Test()
    syms t
    v = [3+t, 3, 6];
    disp(v);
end

Displays the vector: [t + 3, 3, 6]

But now I cannot assign any value to t after this calculation, I cannot change it and do future work with it... it just stays t. But I want do the operation for example enter image description here and then get the t value or keep working with t for other operations. How can I do this, I hope my question is clear? :)

1
  • Why can you not asign the value after the calculation? Its in the documentation how to do it (my first google hit for "assign value to symbolic variable matlab"), can you show what you tried and why you can't? Commented May 6, 2021 at 8:33

1 Answer 1

1

If you want to define a symbolic variable inside a function and assigning values to it from the outside, it needs to be a global variable.

global t
syms t
v = TestFunc();
v3 = v*3;
subs(v3, t, 4)

function v = TestFunc()
    global t
    syms t
    v = [3+t, 3, 6];
    disp(v);
end
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.