Plotting a parabola in two segments
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I'd like to know how to plot the following function, defined by the red lines:
I've previously plotted a rectangle, which is easier because I just draw lines between the different points and that's it, but in this one I don't know how to join the extreme points (1, 1) and (5, 1) with the function y = sqrt(x) instead of a straight line.
Thanks.
matlab plot matlab-figure
add a comment |
I'd like to know how to plot the following function, defined by the red lines:
I've previously plotted a rectangle, which is easier because I just draw lines between the different points and that's it, but in this one I don't know how to join the extreme points (1, 1) and (5, 1) with the function y = sqrt(x) instead of a straight line.
Thanks.
matlab plot matlab-figure
Hint: you can draw any curve by approximating it with short bits of straight line.
– Cris Luengo
Nov 24 '18 at 14:09
Did none of the answers below solve your problem?
– EBH
Dec 2 '18 at 6:51
add a comment |
I'd like to know how to plot the following function, defined by the red lines:
I've previously plotted a rectangle, which is easier because I just draw lines between the different points and that's it, but in this one I don't know how to join the extreme points (1, 1) and (5, 1) with the function y = sqrt(x) instead of a straight line.
Thanks.
matlab plot matlab-figure
I'd like to know how to plot the following function, defined by the red lines:
I've previously plotted a rectangle, which is easier because I just draw lines between the different points and that's it, but in this one I don't know how to join the extreme points (1, 1) and (5, 1) with the function y = sqrt(x) instead of a straight line.
Thanks.
matlab plot matlab-figure
matlab plot matlab-figure
edited Nov 24 '18 at 23:19
EBH
9,50832351
9,50832351
asked Nov 23 '18 at 16:36
Nicolás UlmeteNicolás Ulmete
132
132
Hint: you can draw any curve by approximating it with short bits of straight line.
– Cris Luengo
Nov 24 '18 at 14:09
Did none of the answers below solve your problem?
– EBH
Dec 2 '18 at 6:51
add a comment |
Hint: you can draw any curve by approximating it with short bits of straight line.
– Cris Luengo
Nov 24 '18 at 14:09
Did none of the answers below solve your problem?
– EBH
Dec 2 '18 at 6:51
Hint: you can draw any curve by approximating it with short bits of straight line.
– Cris Luengo
Nov 24 '18 at 14:09
Hint: you can draw any curve by approximating it with short bits of straight line.
– Cris Luengo
Nov 24 '18 at 14:09
Did none of the answers below solve your problem?
– EBH
Dec 2 '18 at 6:51
Did none of the answers below solve your problem?
– EBH
Dec 2 '18 at 6:51
add a comment |
2 Answers
2
active
oldest
votes
I think, this is what you want to achieve. The keypoint being I guess, you were not sure that how to calculate the y-coordinate value. That is, when I plote the vertical red line, for the y coordinate, I input sqrt(5). This you see in the 9th line in the code snippet below.
clear;
clc;
figure(1);
clf;
x=0:0.01:6;
y=sqrt(x);
plot(x,y, 'LineWidth',2);
hold on;
plot([1 5], [1 1], 'r', 'LineWidth',2);
plot([5 5], [sqrt(5) 1], 'r', 'LineWidth',2);
grid on;
xlim([-2 6]);
ylim([-1 3]);
xlabel('x');
ylabel('y');
title('y=sqrt(x)');
text(1.01, 0.85,'(1; 1)', 'HorizontalAlignment','left', 'FontSize', 12, ...
'FontWeight', 'bold')
text(5.01, 0.85,'(5; 1)', 'HorizontalAlignment','left', 'FontSize', 12, ...
'FontWeight', 'bold')
text(2,0.5+sqrt(2),'downarrow y=surd x', 'HorizontalAlignment','left' ...
, 'FontSize', 12, 'FontWeight', 'bold')
add a comment |
You can do it with this short piece of code:
y = @(x) sqrt(x);
fplot(y,[0 6])% draw the function between x=0 to x=6
hold on
fplot(y,[1 5],'r') % draw the red part of the function
plot([1 5;5 5],[1 1;1 y(5)],'r') % draw the straight lines
hold off
grid on
xlim([-2 6])
ylim([-1 3])
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53450244%2fplotting-a-parabola-in-two-segments%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
I think, this is what you want to achieve. The keypoint being I guess, you were not sure that how to calculate the y-coordinate value. That is, when I plote the vertical red line, for the y coordinate, I input sqrt(5). This you see in the 9th line in the code snippet below.
clear;
clc;
figure(1);
clf;
x=0:0.01:6;
y=sqrt(x);
plot(x,y, 'LineWidth',2);
hold on;
plot([1 5], [1 1], 'r', 'LineWidth',2);
plot([5 5], [sqrt(5) 1], 'r', 'LineWidth',2);
grid on;
xlim([-2 6]);
ylim([-1 3]);
xlabel('x');
ylabel('y');
title('y=sqrt(x)');
text(1.01, 0.85,'(1; 1)', 'HorizontalAlignment','left', 'FontSize', 12, ...
'FontWeight', 'bold')
text(5.01, 0.85,'(5; 1)', 'HorizontalAlignment','left', 'FontSize', 12, ...
'FontWeight', 'bold')
text(2,0.5+sqrt(2),'downarrow y=surd x', 'HorizontalAlignment','left' ...
, 'FontSize', 12, 'FontWeight', 'bold')
add a comment |
I think, this is what you want to achieve. The keypoint being I guess, you were not sure that how to calculate the y-coordinate value. That is, when I plote the vertical red line, for the y coordinate, I input sqrt(5). This you see in the 9th line in the code snippet below.
clear;
clc;
figure(1);
clf;
x=0:0.01:6;
y=sqrt(x);
plot(x,y, 'LineWidth',2);
hold on;
plot([1 5], [1 1], 'r', 'LineWidth',2);
plot([5 5], [sqrt(5) 1], 'r', 'LineWidth',2);
grid on;
xlim([-2 6]);
ylim([-1 3]);
xlabel('x');
ylabel('y');
title('y=sqrt(x)');
text(1.01, 0.85,'(1; 1)', 'HorizontalAlignment','left', 'FontSize', 12, ...
'FontWeight', 'bold')
text(5.01, 0.85,'(5; 1)', 'HorizontalAlignment','left', 'FontSize', 12, ...
'FontWeight', 'bold')
text(2,0.5+sqrt(2),'downarrow y=surd x', 'HorizontalAlignment','left' ...
, 'FontSize', 12, 'FontWeight', 'bold')
add a comment |
I think, this is what you want to achieve. The keypoint being I guess, you were not sure that how to calculate the y-coordinate value. That is, when I plote the vertical red line, for the y coordinate, I input sqrt(5). This you see in the 9th line in the code snippet below.
clear;
clc;
figure(1);
clf;
x=0:0.01:6;
y=sqrt(x);
plot(x,y, 'LineWidth',2);
hold on;
plot([1 5], [1 1], 'r', 'LineWidth',2);
plot([5 5], [sqrt(5) 1], 'r', 'LineWidth',2);
grid on;
xlim([-2 6]);
ylim([-1 3]);
xlabel('x');
ylabel('y');
title('y=sqrt(x)');
text(1.01, 0.85,'(1; 1)', 'HorizontalAlignment','left', 'FontSize', 12, ...
'FontWeight', 'bold')
text(5.01, 0.85,'(5; 1)', 'HorizontalAlignment','left', 'FontSize', 12, ...
'FontWeight', 'bold')
text(2,0.5+sqrt(2),'downarrow y=surd x', 'HorizontalAlignment','left' ...
, 'FontSize', 12, 'FontWeight', 'bold')
I think, this is what you want to achieve. The keypoint being I guess, you were not sure that how to calculate the y-coordinate value. That is, when I plote the vertical red line, for the y coordinate, I input sqrt(5). This you see in the 9th line in the code snippet below.
clear;
clc;
figure(1);
clf;
x=0:0.01:6;
y=sqrt(x);
plot(x,y, 'LineWidth',2);
hold on;
plot([1 5], [1 1], 'r', 'LineWidth',2);
plot([5 5], [sqrt(5) 1], 'r', 'LineWidth',2);
grid on;
xlim([-2 6]);
ylim([-1 3]);
xlabel('x');
ylabel('y');
title('y=sqrt(x)');
text(1.01, 0.85,'(1; 1)', 'HorizontalAlignment','left', 'FontSize', 12, ...
'FontWeight', 'bold')
text(5.01, 0.85,'(5; 1)', 'HorizontalAlignment','left', 'FontSize', 12, ...
'FontWeight', 'bold')
text(2,0.5+sqrt(2),'downarrow y=surd x', 'HorizontalAlignment','left' ...
, 'FontSize', 12, 'FontWeight', 'bold')
edited Nov 23 '18 at 18:30
answered Nov 23 '18 at 18:18
Joey MalloneJoey Mallone
2,31861933
2,31861933
add a comment |
add a comment |
You can do it with this short piece of code:
y = @(x) sqrt(x);
fplot(y,[0 6])% draw the function between x=0 to x=6
hold on
fplot(y,[1 5],'r') % draw the red part of the function
plot([1 5;5 5],[1 1;1 y(5)],'r') % draw the straight lines
hold off
grid on
xlim([-2 6])
ylim([-1 3])
add a comment |
You can do it with this short piece of code:
y = @(x) sqrt(x);
fplot(y,[0 6])% draw the function between x=0 to x=6
hold on
fplot(y,[1 5],'r') % draw the red part of the function
plot([1 5;5 5],[1 1;1 y(5)],'r') % draw the straight lines
hold off
grid on
xlim([-2 6])
ylim([-1 3])
add a comment |
You can do it with this short piece of code:
y = @(x) sqrt(x);
fplot(y,[0 6])% draw the function between x=0 to x=6
hold on
fplot(y,[1 5],'r') % draw the red part of the function
plot([1 5;5 5],[1 1;1 y(5)],'r') % draw the straight lines
hold off
grid on
xlim([-2 6])
ylim([-1 3])
You can do it with this short piece of code:
y = @(x) sqrt(x);
fplot(y,[0 6])% draw the function between x=0 to x=6
hold on
fplot(y,[1 5],'r') % draw the red part of the function
plot([1 5;5 5],[1 1;1 y(5)],'r') % draw the straight lines
hold off
grid on
xlim([-2 6])
ylim([-1 3])
edited Nov 24 '18 at 23:11
answered Nov 24 '18 at 23:06
EBHEBH
9,50832351
9,50832351
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53450244%2fplotting-a-parabola-in-two-segments%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Hint: you can draw any curve by approximating it with short bits of straight line.
– Cris Luengo
Nov 24 '18 at 14:09
Did none of the answers below solve your problem?
– EBH
Dec 2 '18 at 6:51