can i define some equation using the symbolic variables t1 and t2, then later assign one of them a value for the purpose of solving for the other? in matlab

You can define an equation using the symbolic variables t1 and t2 using the sym function in MATLAB. Here's an example:

main.m
syms t1 t2

eqn = t1 + 2*t2 == 5;
34 chars
4 lines

This creates a symbolic equation eqn which can be solved for t1 or t2.

To solve for one of the variables, you can use the solve function in MATLAB. Here's an example:

main.m
sol = solve(eqn, t1);

% Now you can assign a value to t2 and evaluate t1
t2_val = 1;
t1_val = subs(sol, t2, t2_val); % Evaluate t1 with t2 = t2_val
149 chars
6 lines

This will give you the solution for t1 when t2 = 1.

Alternatively, you can solve for t2 instead by swapping the symbolic variables in the equation and using the solve function again:

main.m
eqn2 = t2 + 2*t1 == 5;

sol2 = solve(eqn2, t2);

% Now you can assign a value to t1 and evaluate t2
t1_val = 1;
t2_val = subs(sol2, t1, t1_val); % Evaluate t2 with t1 = t1_val
176 chars
8 lines

This will give you the solution for t2 when t1 = 1.

related categories

gistlibby LogSnag