Help me plot my first function, please
5 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Magnarok
am 13 Feb. 2017
Kommentiert: Magnarok
am 13 Feb. 2017
Hello. I'm a complete beginner when it comes to MATLAB and couldn't find a question that helped me. (Probably because I don't know the right terms to search). Sorry.
Why can't I plot this function? It worked on a smaller scale in a test file i made.
I get error: "Undefined function or variable 'r'." But I defined it in the function.
tx = 40 * 10^-10;
ex = 3.45*10^-13;
on = 180;
Vn = 0.25;
WLn = 0.12/1.4;
B = (on * (ex/tx)*WLn)
fplot(r)
function r = In(Vsn)
r = B*(1.2 - Vn - (Vsn/2))*Vsn
end
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 13 Feb. 2017
You could use:
tx = 40 * 10^-10;
ex = 3.45*10^-13;
on = 180;
Vn = 0.25;
WLn = 0.12/1.4;
B = (on * (ex/tx)*WLn);
r = @(Vsn) B*(1.2 - Vn - (Vsn/2)).*Vsn;
fplot(r)
The above can be used as a script file.
Any variable that you define in a function only exists while the function is executing.
You were not executing the function named In at all.
Also, your function used values that were defined in the script and not passed into the function.
You could also have used
function my_first_plot
tx = 40 * 10^-10;
ex = 3.45*10^-13;
on = 180;
Vn = 0.25;
WLn = 0.12/1.4;
fplot(@In)
function r = In(Vsn)
r = B*(1.2 - Vn - (Vsn/2))*Vsn
end
end
This is a more advanced program that shares variables with a nested function.
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Graphics Objects finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!