Multiple functions on one graph

조회 수: 10 (최근 30일)
Rookie
Rookie 2015년 10월 28일
댓글: IMRAN NAZEER 2021년 5월 28일
Hi I'm new to MATLAB and wanted to graph the below four functions on one graph. But for some reason I continue to get an unable to graph. For back ground, just checking a perturbation problem solution as compared to the exact solution.{y''+2y'+y=0, y(0)=0, y(1)=1}
clear; clc;
epsilon = 10^(-4);
x = 0:1;
y1 = x*exp(1-x); %exact solution
y2 = exp(.5)*(1-exp(x/epsilon)); %inner solution
y3 = exp(.5*(x+1)); %outer solution
y4 = exp(.5)*(exp((-x/2))-exp(-1*(2*x)/epsilon)); %composite solution
plot(x,y1,'color','r'); hold on;
plot(x,y2,'color','b'); hold on;
plot(x,y3,'color','y'); hold on;
plot(x,y4,'color','g');
  댓글 수: 2
Image Analyst
Image Analyst 2015년 10월 28일
You only have 2 points - 2 x values with their associated 2 y values. Is that what you want? Maybe use linspace() to get x.
IMRAN NAZEER
IMRAN NAZEER 2021년 5월 28일
How we will plot graph of 3 functions using plot command without hold on and hold off?? Kindly urgent guide me plz

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

채택된 답변

Elon
Elon 2015년 10월 28일
Look into the documentation for the times operator. I think you may want something like:
y1=x.*exp(1-x)
  댓글 수: 1
Rookie
Rookie 2015년 10월 30일
Thank you very much, that worked. Going to look up the point of the period after the x. Thanks again.

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by