Vraag over Matlab
-
- Berichten: 7
Vraag over Matlab
Dag,
Ik krijg de volgende vraag bij Matlab (zie bijlage). Ik weet dat ik hiervoor de functie 'for loop', 'if' of 'while' moet toepassen, maar ik zou niet weten hoe. Is er iemand die mij kan vertellen hoe ik dit moet toepassen.
Met vriendelijke groet,
Wouter
Ik krijg de volgende vraag bij Matlab (zie bijlage). Ik weet dat ik hiervoor de functie 'for loop', 'if' of 'while' moet toepassen, maar ik zou niet weten hoe. Is er iemand die mij kan vertellen hoe ik dit moet toepassen.
Met vriendelijke groet,
Wouter
- Bijlagen
-
- Question matlab.docx
- (76.6 KiB) 118 keer gedownload
- Moderator
- Berichten: 4.106
Re: Vraag over Matlab
Kun je je vraag hier op het forum posten, i.p.v. in een bijlage?
-
- Berichten: 7
Re: Vraag over Matlab
Definition: a vector v with n elements, n > 1, is increasing up to and including the k-the element if the following applies to elements vj of v:
v1 ≤ v2 ≤ v3 ≤ … ≤ vk-1 ≤ vk and, only in case k < n, vk > vk+1
Example: the vector v = [-1,5 , π , 5 , wortel(29.5), 3.5 , 12π, 49] is increasing up to and including the fourth element, hence k = 4.
i) Define a function with input the vector v and as output the value of k for which the vector v is increasing up to and including the k-the element. You don’t may use the commands break, return or continue or standard routines with the exception of length.
The function must not display (any) results.
ii) Test this function on ‘all’ possible outcomes of k and at various values of n.
v1 ≤ v2 ≤ v3 ≤ … ≤ vk-1 ≤ vk and, only in case k < n, vk > vk+1
Example: the vector v = [-1,5 , π , 5 , wortel(29.5), 3.5 , 12π, 49] is increasing up to and including the fourth element, hence k = 4.
i) Define a function with input the vector v and as output the value of k for which the vector v is increasing up to and including the k-the element. You don’t may use the commands break, return or continue or standard routines with the exception of length.
The function must not display (any) results.
ii) Test this function on ‘all’ possible outcomes of k and at various values of n.
- Moderator
- Berichten: 4.106
Re: Vraag over Matlab
Kun je laten zien wat je al hebt geprobeerd?
-
- Berichten: 7
Re: Vraag over Matlab
function [k] = until_k(v)
k = 1;
while k<length(v) && v(k)>v(k+1)
k = k + 1;
end
end
Maar dan weet ik ook niet wat ik bij die tweede vraag moet doen...
k = 1;
while k<length(v) && v(k)>v(k+1)
k = k + 1;
end
end
Maar dan weet ik ook niet wat ik bij die tweede vraag moet doen...
- Moderator
- Berichten: 4.106
Re: Vraag over Matlab
Bij die tweede vraag moet je test cases verzinnen waarbij die k allerlei verschillende waarden aanneemt, bijvoorbeeld tweede element is al niet meer stijgend, middelste element is niet meer stijgend, alles is stijgend en misschien wel nog enkele randgevallen.
- Moderator
- Berichten: 4.106
Re: Vraag over Matlab
De bedoeling is dat je je programma dat je bij a geschreven hebt meerdere malen uitvoert, steeds met andere parameters. Dit kun je in een scriptje zetten in Matlab.
-
- Berichten: 7
Re: Vraag over Matlab
Maar welke parameter in die functie moet ik steeds veranderen dan?
-
- Berichten: 7
Re: Vraag over Matlab
Laat maar.. Ik snap het momenteel. In ieder geval bedankt!