필터 지우기
필터 지우기

How to plot several different points from an equation? (Macaulay's notation)

조회 수: 3 (최근 30일)
Edvardas
Edvardas 2012년 10월 22일
Hello,
I am fairly new to Matlab and thought of using it for one project to plot some graphs. Problem is it requires Macaulay's notation. At the moment I've come up with a function file like this:
function [ V ] = Untitled2( x )
%UNTITLED2 Summary of this function goes here
% Detailed explanation goes here;
R1h= 632.568;
R2h= -2722.793;
Th= -2090.455;
A=x;
B=x-0.76;
C=x-0.99;
if A>0
A=1;
else
A=0;
end
if B>0
B=1;
else
B=0;
end
if C>0
C=1;
else
C=0;
end
V=R1h*A+R2h*B+Th*C;
plot(x, V);
end
Now, it gives the correct values for the shear force V whenever I add a specific coordinate x, however I can't think of a way for it to plot all the points. To be more precise I need it to be at V= 632.568 up until x=0.76, then it should go down straight to V= -2090.455 up until x=0.99 and then return to 0.
If any advice could be given about how to plot such a graph (or make better use of Matlab for Macaulay's notation) I would really appreciate!
Thanks!

답변 (2개)

Walter Roberson
Walter Roberson 2012년 10월 22일
Remove the plot() statement. Then in a new driver routine use
V = arrayfun(@Untitled2, x); %x can be a vector
plot(x, V);
  댓글 수: 1
Edvardas
Edvardas 2012년 10월 22일
편집: Edvardas 2012년 10월 22일
Thank you for such a quick reply!
It seemed to have worked halfway only though, the figure now seems to show the correct range of numbers on x and V axis, however it doesn't draw the graph itself. (Not sure if relevant, but used x as a matrix 0:0.01:0.99). So a little bit confused now, can anything be done about that?
Edit: Just noticed the negative x values, not sure why they're there, considering the matrix I added was from 0 to 0.99.

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


Matt Fig
Matt Fig 2012년 10월 22일
편집: Matt Fig 2012년 10월 22일
function [ V ] = Untitled2(x)
V = zeros(size(x));
V(x<=.76) = 632.568;
V(x>.76 & x<=.99) = -2090.455;
Now, from the command line:
x = 0:.001:1.5;
plot(x,Untitled2(x))
Also, why not name your function some useful name, like:
function V = shearforce(x)
V = zeros(size(x));
V(x<=.76) = 632.568;
V(x>.76 & x<=.99) = -2090.455;
This 'Untitled2' business is just awful!
  댓글 수: 1
Edvardas
Edvardas 2012년 10월 22일
Thanks! Works like a charm for shear force. Was hoping that it would be possible to do with my initial try, as that would be quite easy to transform into a bending moment function as well. Will try to figure out something along this path as well :)
And yes, good point with the naming, got too enthusiastic with Matlab whilst trying to figure out how to do the function, completely forgot about renaming!

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

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by