Reputation: 19
I'm very new to Matlab and have problem plotting this nonlinear 2D function graph using Matlab.
a lot of errors generated after the below is run.
fun1 = 20 + 10 + 15;
fun2 = 20 + (x * 0.00125 ) + 15;
fun3 = (x * 0.0025) + 15;
fplot(fun1,[0 8000])
fplot(fun2,[8000 16000])
fplot(fun2,[16000 positive infinity])
I appreciate a lot to your efforts and kindness for replying my question Best Regards
Upvotes: 0
Views: 2102
Reputation: 475
If you do some reading in fplot you will find out that for fplot(fun,limits) fun must be
so in your case you need to change all of you fun to strings just add ' before and after the expression
as for the last line change it to be
fplot(fun2,[16000 inf])
although i don't think this would give you any good results
Upvotes: 0
Reputation: 36710
Your first three expressions do not define functions. Please read the documentation about the correct syntax.
fun1 = @(x)(20 + 10 + 15);
Upvotes: 1
Reputation: 47392
First create a file fun.m
which contains your function definition
function y = fun(x)
if x < 8000
y = 20 + 10 + 15;
elseif x < 16000
y = 20 + (x * 0.00125) + 15;
else
y = x * 0.0025 + 15;
end
end
Then you can plot it with
fplot(@fun, [0 24000])
which results in
Upvotes: 0