Tp4-Matlab Function
Tp4-Matlab Function
Questions :
1. Edit these two files in the same current folder and execute main.m.
2. What is the content of the sqr.m file?
3. What is the purpose of the statement on line 2 in main.m?
4. Describe the meaning and usage of variables x and y in sqr.m.
5. Explain the distinctions between the sqr function, fprintf, and input.
6. Compare the variables x and y defined within the sqr function with those in the main script.
7. After line 3 in main.m, insert the following code:
V = [1 2 3];
yy = sqr(v);
disp(yy);
Execute the script and report your observations. If there are any issues, provide guidance on how to
resolve them.
8. Can you redefine the sqr function within main.m using the @ anonymous function notation?
1
Part II
keyboard.
main.m my_hypot.m
clc function …… = my_hypot(………………)
clear
……………………………… …………………………………………
………………………………….. ………………………………………….
………………………………
end
In main.m script, make sure to incorporate the input of values for xa, ya, xb, and yb from the keyboard to
solve questions b and c of Task 3.
2
Additionnal exercises
Reminder :
.𝒏! = 𝟏 × 𝟐 × 𝟑 × … . .× (𝒏 − 𝟏) × 𝒏
𝒙𝟐 𝒙𝟑 𝒙𝒌
.𝒆𝒙 = 𝟏 + 𝒙 + + + ...+ + . . . with 𝒌 = 𝟎. . 𝒏 /number of terms
𝟐! 𝟑! 𝒌!
𝒙𝟐 𝒙𝟒 𝒙𝟔 (−𝟏)𝒌 𝒙𝟐𝒌
.𝒄𝒐𝒔(𝒙) = 𝟏 − + − + ...+ (𝟐𝒌)!
+ . . . with 𝒌 = 𝟎. . 𝒏 / number of terms
𝟐! 𝟒! 𝟔!
𝒙𝟑 𝒙𝟓 𝒙𝟕 (−𝟏)𝒌 𝒙𝟐𝒌+𝟏
.𝒔𝒊𝒏(𝒙) = 𝒙 − 𝟑!
+ 𝟓!
− 𝟕!
+ ...+ (𝟐𝒌+𝟏)!
+ . . . with 𝑘 = 𝟎. . 𝒏 / number of terms