How to find a Y value of a given X?

97 ビュー (過去 30 日間)
Rishab Vadvadgi
Rishab Vadvadgi 2020 年 9 月 17 日
コメント済み: Star Strider 2020 年 9 月 17 日
Hello, this is a very simple question. I am writing an equation for v given t:
t = 0:0.00001:0.01;
v= 50*exp(-1600*t) - 50*exp(-400*t);
How would I find the value of v at a certain t? I want to find what v is when t=0.000625.

採用された回答

Star Strider
Star Strider 2020 年 9 月 17 日
This is easiest if you create ‘v’ as an anonymous function:
t = 0:0.00001:0.01;
v = @(t) 50*exp(-1600*t) - 50*exp(-400*t);
ti = 0.000625;
Out = v(ti)
figure
plot(t, v(t))
hold on
plot(ti, v(ti), 'r+')
hold off
grid
See Anonymous Functions for details.
  3 件のコメント
Rishab Vadvadgi
Rishab Vadvadgi 2020 年 9 月 17 日
Thanks! I ended up figuring out right after I posted haha
Star Strider
Star Strider 2020 年 9 月 17 日
My pleasure!
To calculate with functions, it is necessary to evaluate them to do the calculation:
p = @(t) v(t).*i(t);
That works. Note also the use of element-wise multiplication, .* instead of * .
Example —
figure
plot(t, p(t))
grid
.

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

その他の回答 (2 件)

Johannes Fischer
Johannes Fischer 2020 年 9 月 17 日
You want to use an anonymous function.
So in your case:
% define the anonymous function
v = @(t) 50*exp(-1600*t) - 50*exp(-400*t);
% call it
v(0.000625)
  1 件のコメント
Rishab Vadvadgi
Rishab Vadvadgi 2020 年 9 月 17 日
編集済み: Rishab Vadvadgi 2020 年 9 月 17 日
Thank you! One more question: can I use functions I have written to create a new one? For example, I am trying to multiply a function v and a function i together to make a new function p.
v = @(t) 50*exp(-1600*t) - 50*exp(-400*t);
i = @(t) (5*exp(-1600*t) - 5*exp(-400*t)) * 0.001;
p = @(t) v*i;
However, this gives me an error. What is the proper way to do this?

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


BOB MATHEW SYJI
BOB MATHEW SYJI 2020 年 9 月 17 日
Hope this helps. x is the input and sol is the value of v at x (in this case x=0.000625)
syms v(t)
x=0.000625;
v(t)= 50*exp(-1600*t) - 50*exp(-400*t);
sol=double(v(x));

カテゴリ

Help Center および File ExchangeCalculus についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by