error with graphing exp function

in my code I tried having e to some negative power and graph it but it's not working, any help?
r = 0.5; l=4;
%%given: A(1) and A(2) are two numbers from a vector, and r(1) and r(2) are two other numbers from another vector
vct = A(1)*exp(r(2)*x)+ A(2)*exp(r(1)*x);
x = 0:2:20
figure
expfunc = exp(-x*r/l) %%I want e^(-x*r/l) for that part
plot(x,vct/0.5*(1-expfunc)) %%overall equation should be: vct/0.5*(1-e^(-x*r/l))

7 件のコメント

madhan ravi
madhan ravi 2019 年 4 月 11 日
r, l ?
James Tursa
James Tursa 2019 年 4 月 11 日
If x is a vector and r is a vector, what do you expect from the expression -x*r/l?
seldiora
seldiora 2019 年 4 月 11 日
oh no, x isn't a vector, it's a variable, r and l are set in the beginning
James Tursa
James Tursa 2019 年 4 月 11 日
This line makes x a vector:
>> x = 0:2:20
x =
0 2 4 6 8 10 12 14 16 18 20
Then you have text that says r is a two element vector since you use r(1) and r(2). But your code has r as a scalar. So which is it?
seldiora
seldiora 2019 年 4 月 11 日
編集済み: seldiora 2019 年 4 月 11 日
ah, I re-set r into a vector. So how would I fix this? Graphing vct itself didn't cause any problems.
edit: oh, r isn't meant to be a vector. I solved that but that wasn't the entire problem
James Tursa
James Tursa 2019 年 4 月 11 日
I could fix your code so it didn't generate errors, but it might not be correct for the problem you are trying to solve. Can you give us the actual wording of the assignment?
seldiora
seldiora 2019 年 4 月 11 日
so, I want to graph the current for an inductor. [http://hyperphysics.phy-astr.gsu.edu/hbase/electric/imgele/indt.png] However since the voltage (vct) varies with time, I want to use vct/r*... [the rest is in the image]

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

回答 (0 件)

カテゴリ

ヘルプ センター および File Exchange2-D and 3-D Plots についてさらに検索

製品

リリース

R2017a

タグ

質問済み:

2019 年 4 月 11 日

編集済み:

2019 年 4 月 11 日

Community Treasure Hunt

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

Start Hunting!

Translated by