Solve for, and then substitute.

3 visualizaciones (últimos 30 días)
Kyle Langford
Kyle Langford el 18 de Feb. de 2022
Comentada: Kyle Langford el 19 de Feb. de 2022
I posted before, but I am not getting the answers I am looking for. This is a simplified version of what I want to do.
say, f(t)=y*t, and we are given an initial condition f(1)=10. We can use this information to solve for y..
Now that we know, y=10, solve for f(2)=?, obviously f(2) will equal 20.
How can I write this code in MATLAB?
  2 comentarios
Kyle Langford
Kyle Langford el 19 de Feb. de 2022
Editada: Walter Roberson el 19 de Feb. de 2022
I am trying to solve this:
given
y(1.2)=80
, and the equation
y(t)==K*A + (y0-K*A)*exp(-t/T)
K=1
A=100
y0=0
y_t=80 %y(1.2)=80
t=1.2
eq1=y_t==K*A + (y0-K*A)*exp(-t/T)
vpasolve(eq1,T)
This gives me that T=0.7456.
Now using knowing T, solve for y(1.5)
Kyle Langford
Kyle Langford el 19 de Feb. de 2022
I can do this, but i was trying but I am trying to find a more creative way to code this.
clear;clc;
syms x
syms
K=1
A=100
y0=0
y_t=80 %y(1.2)=80
t=1.2 %subs for t=1.5
eq1=y_t==K*A + (y0-K*A)*exp(-t/x)
T=vpasolve(eq1,x)
clear eq1
y=@(t) K*A + (y0-K*A)*exp(-t/T)
y(1.5)

Iniciar sesión para comentar.

Respuesta aceptada

Walter Roberson
Walter Roberson el 19 de Feb. de 2022
K=1
K = 1
A=100
A = 100
y0=0
y0 = 0
syms y(t) T
y(t) = K*A + (y0-K*A)*exp(-t/T)
y(t) = 
y_known = 80 %y(1.2)=80
y_known = 80
t_known = 1.2
t_known = 1.2000
eq1 = y(t_known) == y_known
eq1 = 
sol_T = solve(eq1, T)
sol_T = 
y(t) = subs(y(t), T, sol_T)
y(t) = 
y(1.5)
ans = 
vpa(ans)
ans = 
86.625193900471559519935338534827

Más respuestas (1)

Arif Hoq
Arif Hoq el 18 de Feb. de 2022
Editada: Arif Hoq el 18 de Feb. de 2022
you can use anonymous function:
y=10;
f=@(t) y*t;
f(1)
ans = 10
f(2)
ans = 20
  1 comentario
Kyle Langford
Kyle Langford el 19 de Feb. de 2022
Although that does work, that is not what I asked. In this specific scenario, it is easy to figure out y. In a more complex scenario, it would not be so easy.
I think you are on to something, but how could you solve for y given the initial condition f(1)=10, and then additionally solve for f(2) using code?

Iniciar sesión para comentar.

Categorías

Más información sobre Mathematics en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by