evaluating functions and plotting

조회 수: 6 (최근 30일)
sumaiya hossain
sumaiya hossain 2022년 8월 5일
댓글: sumaiya hossain 2022년 8월 5일
evaluate and plot:
What I did for this question was I put each of the equations into a variable : eqn, eqn2 , eqn3 then from that I substituted the x values that apply to each equation and saved it as a , b , c. However I am unsure to how I would plot the graph into one as they are saved as 3 different variables.
First I assumed I would have to plot each graph separately but I am unsure if that is correct or not.
can I get some advice if plotting 3 different graphs for each variable is reasonable or there is another approach I should take.
syms x
eqn = 2*x^2
eqn = 
a = subs(eqn,x,(0<x)&(1>=x));
eqn2 = x^2 + 3
eqn2 = 
b = subs(eqn2,x,(1<x)&(3>=x))
b = 
eqn3 = -3*x
eqn3 = 
c = subs(eqn3,x,(3<x)&(5>=x))
c = 

채택된 답변

Torsten
Torsten 2022년 8월 5일
Use "piecewise" if you want to work with symbolic variables and functions.
Otherwise
f = @(x)2*x.^2.*(x>0 &x<=1) + (x.^2+3).*(x>1&x<=3) + (-3*x).*(x>3&x<=5);
x = 0:0.01:5;
plot(x,f(x))
  댓글 수: 1
sumaiya hossain
sumaiya hossain 2022년 8월 5일
Thank you! Yes i was unsure if you could actully plot it together, I understand now. :)

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Calculus에 대해 자세히 알아보기

제품


릴리스

R2022a

Community Treasure Hunt

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

Start Hunting!

Translated by