Bit of help with piecewise and parametric functions in MATLAB?

Click For Summary
SUMMARY

The discussion focuses on resolving issues with piecewise and parametric functions in MATLAB. The user initially struggled with missing graphs due to incorrect subplot commands and the use of matrix operators instead of array operators. The solution involved correcting the subplot command to (1,2,1) and (1,2,2) and using array operators for the parametric curve. Additionally, the user learned to concatenate vectors for piecewise functions effectively.

PREREQUISITES
  • Basic understanding of MATLAB syntax and commands
  • Familiarity with plotting functions in MATLAB
  • Knowledge of piecewise functions and their implementation
  • Understanding of array vs. matrix operations in MATLAB
NEXT STEPS
  • Explore MATLAB's documentation on creating plots and subplots
  • Learn about function handles in MATLAB for more efficient coding
  • Research techniques for defining piecewise functions in MATLAB
  • Study the differences between array and matrix operations in MATLAB
USEFUL FOR

This discussion is beneficial for MATLAB beginners, students working on assignments involving piecewise and parametric functions, and anyone looking to improve their plotting skills in MATLAB.

korobeiniki
Messages
2
Reaction score
0
Hi guys, after using the forum for ages for help I decided to make an account, so hopefully I might be able to contribute something as well, who knows :)
I'm a first timer with MATLAB and have been set an assignment. I'm completely stuck on question one:
Capture1.jpg

The following image shows my code and the resulting figure. For some reason the second (parametric) graph is missing:
Capture2.jpg

Also I'm not really happy with the code - the first function is piecewise but I've written it out as 2 separate functions. Is there some way to define this as one, piecewise, function?
Thanks for reading :)

Edit!: cracked it! my subplot command was all wrong: should've had (1,2,1) and (1,2,2) respectively. Also I was using matrix operators rather than array operators for the parametric curve. Thanks anyway!
 
Last edited:
Physics news on Phys.org
Welcome to PhysicsForums!

First off, place code in-between [CODE ][\CODE ] brackets (remove the space before the final bracket: it maintains your white space and helps increase readability.

Secondly, especially as you're not doing this using function handles, it suffices to treat piece-wise functions, well, piece-wise :smile: Note that you've also got the datapoint at 10 twice (which is okay, since you're not concatenating the two vectors). To concatenate them, just do something like the following, which will put the two vectors together (x1 values followed by x2):

>>x=[x1, x2];

Good for you for figuring out the rest of it! For future reference, the MATLAB web documentation is really, really complete and helpful (even more so than the generic help (function) command in MATLAB):
http://www.mathworks.com/help/techdoc/creating_plots/f6-20079.html#f6-35125
 
Last edited by a moderator:

Similar threads

  • · Replies 1 ·
Replies
1
Views
3K
  • · Replies 8 ·
Replies
8
Views
3K
  • · Replies 4 ·
Replies
4
Views
7K
  • · Replies 1 ·
Replies
1
Views
5K
  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
5K
  • · Replies 1 ·
Replies
1
Views
4K
  • · Replies 1 ·
Replies
1
Views
9K
  • · Replies 5 ·
Replies
5
Views
3K
  • · Replies 6 ·
Replies
6
Views
4K