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)
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일

0 개 추천

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일

0 개 추천

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?

댓글을 달려면 로그인하십시오.

제품

릴리스

R2021b

태그

질문:

2022년 2월 18일

댓글:

2022년 2월 19일

Community Treasure Hunt

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

Start Hunting!

Translated by