plot line with function but doesn't appear like i want

조회 수: 2 (최근 30일)
nirwana
nirwana 2023년 5월 15일
댓글: Walter Roberson 2023년 5월 15일
I have a figure below and i want to reproduce it using matlab figure
.
The diagonal line come from equation x/(sqrt(x^2+a^2)*v1)
Here the code that I write, but it give me straight line, not diagonal one. Could you tell me please which part that i made mistake?
close all, clear,clc
a=linspace(5,0);
x=linspace(0,3.758);
b=linspace(3.758,10-3.758);
c=linspace(0,-3);
v1=4;
v2=6;
left_eq=x./(sqrt(x.^2+a.^2)*v1);
right_eq=(b-x)./(sqrt(c.^2+(b-x).^2)*v2);
plot(x,left_eq,'-b',b,right_eq,'-r')
  댓글 수: 1
Walter Roberson
Walter Roberson 2023년 5월 15일
Your a and x both increase linearly with time, just with different rates. When you run the calculation symbolically you can show that the ratio you are constructing is constant.
a=linspace(0,5);
x=linspace(0,3.758);
denom = sqrt(x.^2 + a.^2);
plot(x, denom)
syms t positive
A = 0 + (5-0)*t
A = 
X = 0 + (3.758-0)*t
X = 
denom = sqrt(A^2 + X.^2)
denom = 
left_eq = X ./ denom
left_eq = 

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

채택된 답변

Matt J
Matt J 2023년 5월 15일
편집: Matt J 2023년 5월 15일
plot([0,3.758,10] , [5,0,-3],'-o','MarkerFaceColor','b'); hold on
plot([0,0],[0,5],':b');
plot([10,10],[0,-3],':b');hold off
yline(0); axis equal; xlim([-3,13])

추가 답변 (0개)

카테고리

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

태그

Community Treasure Hunt

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

Start Hunting!

Translated by