Solve for, and then substitute.

2 次查看(过去 30 天)
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 个评论
Kyle Langford
Kyle Langford 2022-2-19
编辑:Walter Roberson 2022-2-19
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 2022-2-19
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)

请先登录,再进行评论。

采纳的回答

Walter Roberson
Walter Roberson 2022-2-19
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

更多回答(1 个)

Arif Hoq
Arif Hoq 2022-2-18
编辑:Arif Hoq 2022-2-18
you can use anonymous function:
y=10;
f=@(t) y*t;
f(1)
ans = 10
f(2)
ans = 20
  1 个评论
Kyle Langford
Kyle Langford 2022-2-19
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?

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Calculus 的更多信息

标签

产品


版本

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by