0

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

3 Answers 3

1

Your first three expressions do not define functions. Please read the documentation about the correct syntax.

fun1 = @(x)(20 + 10 + 15);
Sign up to request clarification or add additional context in comments.

Comments

0

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

enter image description here

Comments

0

If you do some reading in fplot you will find out that for fplot(fun,limits) fun must be

  • The name of a function
  • A string with variable x that may be passed to eval, such as 'sin(x)', 'diric(x,10)', or '[sin(x),cos(x)]'
  • A function handle

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.