フィルターのクリア

Solve for, and then substitute.

6 ビュー (過去 30 日間)
Kyle Langford
Kyle Langford 2022 年 2 月 18 日
コメント済み: Kyle Langford 2022 年 2 月 19 日
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 件のコメント
Kyle Langford
Kyle Langford 2022 年 2 月 19 日
@Walter Roberson as always, I appreciate you!

サインインしてコメントする。

その他の回答 (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 Center および File ExchangeCalculus についてさらに検索

タグ

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by